Skip to content

Commit a7cc00d

Browse files
authored
Create Ostrichcrab.md
1 parent c73d678 commit a7cc00d

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

2018.12.06-leetcode103/Ostrichcrab.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
```
2+
/**
3+
* Definition for a binary tree node.
4+
* struct TreeNode {
5+
* int val;
6+
* TreeNode *left;
7+
* TreeNode *right;
8+
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
9+
* };
10+
*/
11+
class Solution {
12+
public:
13+
vector<vector<int>> zigzagLevelOrder(TreeNode* root) {
14+
vector<vector<int>> result;
15+
queue<TreeNode*> que;
16+
if(root == NULL) return result;
17+
que.push(root);
18+
while(!que.empty()){
19+
vector<int> tmp;
20+
int size = que.size();
21+
for(int i = 0; i < size; i++){
22+
TreeNode* t = que.front();
23+
que.pop();
24+
tmp.push_back(t->val);
25+
if(t->left) que.push(t->left);
26+
if(t->right) que.push(t->right);
27+
}
28+
result.push_back(tmp);
29+
}
30+
for(int i = 0; i < result.size(); i++){
31+
if(i&1) reverse(result[i].begin(),result[i].end());
32+
}
33+
return result;
34+
}
35+
};
36+
```

0 commit comments

Comments
 (0)