소스 검색

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

Loading…
취소
저장