Kaynağa Gözat

Another one bites the dust

master
Lachlan Jacob 5 yıl önce
ebeveyn
işleme
fb92c4a350
3 değiştirilmiş dosya ile 39 ekleme ve 0 silme
  1. 29
    0
      1379/main.py
  2. 7
    0
      1379/problem.txt
  3. 3
    0
      1379/run.sh

+ 29
- 0
1379/main.py Dosyayı Görüntüle

@@ -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 Dosyayı Görüntüle

@@ -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 Dosyayı Görüntüle

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

python3 main.py

Loading…
İptal
Kaydet