3ms Java Solution


  • 0
    J
    public class Solution {
    public List<Integer> rightSideView(TreeNode root) {
        List<Integer> list = new ArrayList<Integer>();
        if(root == null)
            return list;
        list.add(root.val);
        List<Integer> right = rightSideView(root.right);
        List<Integer> left = rightSideView(root.left);
        list.addAll(right);
        int index = right.size();
        while(index < left.size())
            list.add(left.get(index++));
        return list;
    }
    

    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.