浏览代码

Another one bites the dust

master
Lachlan Jacob 5 年前
父节点
当前提交
fb92c4a350
共有 3 个文件被更改,包括 39 次插入0 次删除
  1. 29
    0
      1379/main.py
  2. 7
    0
      1379/problem.txt
  3. 3
    0
      1379/run.sh

+ 29
- 0
1379/main.py 查看文件

@@ -0,0 +1,29 @@
class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None

class Solution:
def getTargetCopy(self, original: TreeNode, cloned: TreeNode, target: TreeNode) -> TreeNode:
return self.findTarget(cloned, target)
def findTarget(self, tree, t):
if tree is not None:
if tree.val == t.val:
return tree
leftFound = self.findTarget(tree.left, t)
rightFound = self.findTarget(tree.right, t)
if leftFound is not None:
return leftFound
elif rightFound is not None:
return rightFound

s = Solution()
o = TreeNode(1)
o.left = TreeNode(3)
c = TreeNode(1)
t = TreeNode(3)
c.left = t
print("Expected: 3")
print("Got:", s.getTargetCopy(o, c, t).val)

+ 7
- 0
1379/problem.txt 查看文件

@@ -0,0 +1,7 @@
Given two binary trees original and cloned and given a reference to a node target in the original tree.

The cloned tree is a copy of the original tree.

Return a reference to the same node in the cloned tree.

Note that you are not allowed to change any of the two trees or the target node and the answer must be a reference to a node in the cloned tree.

+ 3
- 0
1379/run.sh 查看文件

@@ -0,0 +1,3 @@
#!/bin/bash

python3 main.py

正在加载...
取消
保存