Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

Commit

Permalink
leetcode: finished #1022
Browse files Browse the repository at this point in the history
  • Loading branch information
xqm32 committed Feb 7, 2024
1 parent fd54432 commit c6ee621
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions content/leetcode/2024/2.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,38 @@ title: 2024.2
draft: false
---

# 2024.2.7

```python
#
# @lc app=leetcode.cn id=1022 lang=python3
#
# [1022] 从根到叶的二进制数之和
#

# @lc code=start
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def sumRootToLeaf(self, root: Optional[TreeNode]) -> int:
def dfs(node, val):
if not node:
return 0
val = val * 2 + node.val
if not node.left and not node.right:
return val
return dfs(node.left, val) + dfs(node.right, val)

return dfs(root, 0)


# @lc code=end
```

# 2024.2.6

```python
Expand Down

0 comments on commit c6ee621

Please sign in to comment.