Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit009479c

Browse files
authored
Update 1022. Sum of Root To Leaf Binary Numbers.go
add content of problem
1 parent24e98f4 commit009479c

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

‎1022. Sum of Root To Leaf Binary Numbers.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
/*
2+
Given a binary tree, each node has value 0 or 1. Each root-to-leaf path represents a binary number starting with the most significant bit. For example, if the path is 0 -> 1 -> 1 -> 0 -> 1, then this could represent 01101 in binary, which is 13.
3+
4+
For all leaves in the tree, consider the numbers represented by the path from the root to that leaf.
5+
6+
Return the sum of these numbers.
7+
8+
Example 1:
9+
Input: [1,0,1,0,1,0,1]
10+
Output: 22
11+
Explanation: (100) + (101) + (110) + (111) = 4 + 5 + 6 + 7 = 22
12+
*/
13+
114
package main
215

316
typeTreeNodestruct {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp