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 bbc9da3 commit eac1612Copy full SHA for eac1612
binary-tree-level-order-traversal/PDKhan.cpp
@@ -0,0 +1,35 @@
1
+class Solution {
2
+public:
3
+ vector<vector<int>> levelOrder(TreeNode* root) {
4
+ vector<vector<int>> result;
5
+
6
+ if(!root)
7
+ return result;
8
9
+ queue<TreeNode*> q;
10
11
+ q.push(root);
12
13
+ while(!q.empty()){
14
+ int len = q.size();
15
+ vector<int> level;
16
17
+ for(int i = 0; i < len; i++){
18
+ TreeNode* curr = q.front();
19
+ q.pop();
20
21
+ if(curr->left)
22
+ q.push(curr->left);
23
24
+ if(curr->right)
25
+ q.push(curr->right);
26
27
+ level.push_back(curr->val);
28
+ }
29
30
+ result.push_back(level);
31
32
33
34
35
+};
0 commit comments