I have tested my answer in eclipse and got correct result, but it was judged as wrong here.


  • 0
    S

    /**

    • Definition for binary tree
    • public class TreeNode {
    • int val;
      
    • TreeNode left;
      
    • TreeNode right;
      
    • TreeNode(int x) { val = x; }
      
    • }
      */
      public class Solution {
      public List<Integer> rightSideView(TreeNode root) {
      TreeNode curNode=root;
      List<Integer> rightSideNodes=new ArrayList<Integer>();
      while (curNode !=null) {
      rightSideNodes.add(curNode.val);
      curNode=curNode.right;
      };
      return rightSideNodes;
      }
      }

Log in to reply
 

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