Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- knakul853
- */
- class Solution {
- public:
- vector<int>ans;
- vector<int> rightSideView(TreeNode* root) {
- dfs(root, 0);
- return ans;
- }
- void dfs( TreeNode* root, int lvl)
- {
- if(!root) return;
- if((int)ans.size() == lvl) ans.push_back(root->val);
- dfs(root->left, lvl+1);
- dfs(root->right, lvl+1);
- }
- };
Add Comment
Please, Sign In to add comment