forked from youngyangyang04/leetcode-master
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1a0da92
commit c0be90a
Showing
9 changed files
with
233 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,8 @@ https://leetcode-cn.com/problems/sum-of-left-leaves/ | |
|
||
## C++代码 | ||
|
||
### 递归法 | ||
|
||
``` | ||
class Solution { | ||
public: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
## 地址 | ||
|
||
## 思路 | ||
|
||
## C++代码 | ||
|
||
### 递归法 | ||
|
||
``` | ||
class Solution { | ||
public: | ||
int maxDepth(Node* root) { | ||
if (root == 0) return 0; | ||
int depth = 0; | ||
for (int i = 0; i < root->children.size(); i++) { | ||
depth = max (depth, maxDepth(root->children[i])); | ||
} | ||
return depth + 1; | ||
} | ||
}; | ||
``` | ||
### 迭代法 | ||
|
||
``` | ||
class Solution { | ||
public: | ||
int maxDepth(Node* root) { | ||
queue<Node*> que; | ||
if (root != NULL) que.push(root); | ||
int depth = 0; | ||
while (!que.empty()) { | ||
int size = que.size(); | ||
vector<int> vec; | ||
depth++; | ||
for (int i = 0; i < size; i++) { | ||
Node* node = que.front(); | ||
que.pop(); | ||
for (int i = 0; i < node->children.size(); i++) { | ||
if (node->children[i]) que.push(node->children[i]); | ||
} | ||
} | ||
} | ||
return depth; | ||
} | ||
}; | ||
``` |