File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change
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>> a;
14
+ vector<vector<int>> levelOrderBottom(TreeNode* root) {
15
+ if(!root)
16
+ return a;
17
+
18
+ lot(root,0);
19
+ for(int i=0;i<a.size()/2;i++)
20
+ {
21
+ vector<int> v1;
22
+ v1=a[i];
23
+ a[i]=a[a.size()-1-i];
24
+ a[a.size()-1-i]=v1;
25
+ }
26
+ return a;
27
+ }
28
+ void lot(TreeNode* node,int level)
29
+ {
30
+ if(a.size()<level+1)
31
+ {
32
+ vector<int> v1;
33
+ v1.push_back(node->val);
34
+ a.push_back(v1);
35
+ }
36
+ else
37
+ a[level].push_back(node->val);
38
+
39
+ if(node->left)
40
+ lot(node->left,level+1);
41
+ if(node->right)
42
+ lot(node->right,level+1);
43
+ }
44
+ };
45
+ ```
You can’t perform that action at this time.
0 commit comments