We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 8221bdb commit cc18380Copy full SHA for cc18380
solution/0800-0899/0818.Race Car/Solution.py
@@ -1,12 +1,9 @@
1
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]
+ def pruneTree(self, root):
+ if not root:
+ return None
+ root.left = self.pruneTree(root.left)
+ root.right = self.pruneTree(root.right)
+ if not root.left and not root.right and root.val == 0:
+ return root
0 commit comments