Closed Karthiks08 closed 3 years ago
/**
} */
class Solution { public List rightSideView(TreeNode root) { List result=new ArrayList<>();
if(root==null){ return result; } Queue<TreeNode> q=new LinkedList<>(); q.add(root); while(q.size()>0){ int count=q.size(); while(count-->0){ TreeNode val=q.remove(); if(count==0){ result.add(val.val); } if(val.left!=null){ q.add(val.left); } if(val.right!=null){ q.add(val.right); } } } return result;
} }
/**
} */
class Solution { public List rightSideView(TreeNode root) {
List result=new ArrayList<>();
} }