Skip to content

Commit cc18380

Browse files
Update Solution.py
1 parent 8221bdb commit cc18380

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed
Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
class Solution:
2-
def racecar(self, target: int) -> int:
3-
dp = [0] * (target + 1)
4-
for i in range(1, target + 1):
5-
k = i.bit_length()
6-
if i == 2**k - 1:
7-
dp[i] = k
8-
continue
9-
dp[i] = dp[2**k - 1 - i] + k + 1
10-
for j in range(k - 1):
11-
dp[i] = min(dp[i], dp[i - (2 ** (k - 1) - 2**j)] + k - 1 + j + 2)
12-
return dp[target]
2+
def pruneTree(self, root):
3+
if not root:
4+
return None
5+
root.left = self.pruneTree(root.left)
6+
root.right = self.pruneTree(root.right)
7+
if not root.left and not root.right and root.val == 0:
8+
return None
9+
return root

0 commit comments

Comments
 (0)