当前位置:网站首页>【二叉树-中等】1261. 在受污染的二叉树中查找元素
【二叉树-中等】1261. 在受污染的二叉树中查找元素
2022-08-10 01:52:00 【菜菜2022】
【题目】
【代码】
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class FindElements:
def __init__(self, root: Optional[TreeNode]):
self.root=root
self.num=[]
def dfs(root,parent=-1):
if not root:
return
if parent==-1:
root.val=0
self.num.append(root.val)
if root and root.left:
root.left.val=root.val*2+1
if root and root.right:
root.right.val=root.val*2+2
dfs(root.left,root.val)
dfs(root.right,root.val)
dfs(root)
def find(self, target: int) -> bool:
return target in self.num
边栏推荐
猜你喜欢
随机推荐
进程管理和任务管理
基于FTP协议实现文件上传与下载
3dmax如何制作模型走路动画
按钮倒计时提醒
one of the variables needed for gradient computation has been modified by an inplace
Initial attempt at UI traversal
gbase 8a数据库如何查看数据或数据文件是否正常?
web开发概述
[LeetCode] Find the sum of the numbers from the root node to the leaf node
深度学习(五) CNN卷积神经网络
【QT】QT项目:自制Wireshark
Janus实际生产案例
【二叉树-中等】1104. 二叉树寻路
Under pressure, there must be cowards
浏览器中location详解
c# 解决CS8602告警 解引用可能出现空引用
Interdepartmental Communication Skills
【UNR #6 B】机器人表演(DP)
Problems and solutions related to Chinese character set in file operations in ABAP
openpose脚部标注问题梳理