-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path199-rightSideView.h
More file actions
46 lines (37 loc) · 736 Bytes
/
199-rightSideView.h
File metadata and controls
46 lines (37 loc) · 736 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
43
44
45
#pragma once
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include "TreeDefine.h"
class CSolution
{
public:
CSolution();
~CSolution();
public:
std::vector<int> rightSideView(TreeNode* root);
private:
void help(TreeNode* root, int nlevel, std::vector<int>& res);
};
CSolution::CSolution()
{
}
CSolution::~CSolution()
{
}
std::vector<int> CSolution::rightSideView(TreeNode* root)
{
std::vector<int> vecResult;
help(root, 0, vecResult);
return vecResult;
}
void CSolution::help(TreeNode* root, int nlevel, std::vector<int>& res)
{
if (nullptr == root)
return;
if (res.size() == nlevel)
res.push_back(root->val);
help(root->right, nlevel + 1, res);
help(root->left, nlevel + 1, res);
}