Got different answer from OJ and my eclipse

  • 0

    import java.util.LinkedList;
    import java.util.List;

    public class Solution {
    static List<Integer> a = new LinkedList<Integer>();
    public static List<Integer> preorderTraversal(TreeNode root) {
    //if(root == null)
    //return a;
    if(root.left != null)
    if(root.right != null)
    return a;

    As for input{1,2},my eclipse return right answer but OJ throws a wrong answer with my code{1,1,2}.
    Very weird.

  • 0

    Please correct your code format.

  • 0

    Please refer to the FAQ page for more detail. Especially the question "Why does my code produce a different output compared to my local environment?"

Log in to reply

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