Review
- 199 Binary Tree Right Side View
s
思路: dfs 和 bfs,其实和level order的两种差不多
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
| public void dfs(TreeNode node,List<Integer>res,int level){ if(node==null) return; if(level>=res.size()) res.add(node.val); dfs(node.right,res,level+1); dfs(node.left,res,level+1); } public List<Integer> rightSideView(TreeNode root) { List<Integer>res=new ArrayList<>(); dfs(root,res,0); return res; } public List<Integer>rightSideViewByBFS(TreeNode root){ List<Integer>res=new ArrayList<>(); if(root==null) return res; Queue<TreeNode>q=new LinkedList<>(); while(!q.isEmpty()){ int size= q.size(); while(size -->0){ TreeNode top=q.poll(); if(size==0) res.add(top.val); if(top.left!=null) q.offer(top.left); if(top.right!=null) q.offer(top.right); } } return res; }
|
Expectations
- 改天把internship所涉及到的tech总结一下。
- 要对internship的project表现出激情