Add One Row to Tree LeetCode solution in C++

1
#!/ usr / bin / python
2
#- * - coding : utf - 8 - * -
3
#Definition for a binary tree node.
4
#class TreeNode:
5
#def __init__(self, val = 0, left = None, right = None):
6
#self.val = val
7
#self.left = left
8
#self.right = right
9

10
class Solution :
11

12
def
13
Solve(self, root, val, depth, curr, )
14
: if root == None : return None if depth == 1 : return TreeNode(val, root) if curr
15
== depth - 1 : (left, right) =
16
(root.left, root.right)(root.left, root.right) =
17
(TreeNode(val, left),
18
TreeNode(val, None, right)) return root self.Solve(root.left, val, depth, curr + 1) self
19
.Solve(root.right, val, depth, curr + 1) return root
20

21
def addOneRow(self, root, val, depth, )
22
: return self.Solve(root, val, depth, 1)

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0