# I am new to leetCode? How can we get the solution of the problems that we are solving??

• What is wrong with this solution?

/**

• Definition for binary tree
• public class TreeNode {
• ``````int val;
``````
• ``````TreeNode left;
``````
• ``````TreeNode right;
``````
• ``````TreeNode(int x) { val = x; }
``````
• }
*/

public class Solution {
List<Integer> rightSide = new ArrayList<Integer>();
public List<Integer> rightSideView(TreeNode root) {
if(root == null){
return rightSide;
}
while(root.right!=null){
root=root.right;

``````    }
return rightSide;
}
``````

}

• your loop never end, and your solution is not right, you did not consider the left side, below is my solution:

``````> int curLevel = 0;
> public List<Integer> rightSideView(TreeNode root) {
>     List<Integer> list = new ArrayList<Integer>();
>     dfs(root, 1, list);
>     return list; }
>
> private void dfs(TreeNode node, int level, List<Integer> list) {
>     if (node == null) {
>         return;
>     }
>     if (level > curLevel) {