-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTree1.cpp
More file actions
42 lines (36 loc) · 928 Bytes
/
Copy pathTree1.cpp
File metadata and controls
42 lines (36 loc) · 928 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//Binary Tree Right Side View
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode() : val(0), left(nullptr), right(nullptr) {}
* TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
* TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
* };
*/
int maxl = 0;
vector<int> Fvec;
void utilsrightsideview(TreeNode * root , int CurL)
{
if(root == NULL)
return;
if(maxl<CurL)
{
Fvec.push_back(root->val);
maxl = CurL;
}
utilsrightsideview(root->right,CurL+1);
utilsrightsideview(root->left,CurL+1);
}
class Solution {
public:
vector<int> rightSideView(TreeNode* root) {
Fvec.clear();
maxl = 0;
int curL = 1;
utilsrightsideview(root,curL);
return Fvec;
}
};