Why is this solution not accepted?


  • 0
    W

    The custom test pass, but the same test done when submitting the code fails, why?
    Custom test: [1, 2] 1 -> [1]
    Submit test: [1, 2] 1 -> [1, 2]

    class Solution {
        
        static int nodeFromEnd = 0;
        
        public ListNode removeNthFromEnd(ListNode head, int n) {
            
            if (head.next != null) head.next = removeNthFromEnd(head.next, n);
            
                nodeFromEnd++;
            
             if (nodeFromEnd==n) {
                
                 return head.next;
                
             }
            
            return head;
        }
    }
    

  • 0
    M

    Because you're explicitly requesting to get shot in your foot.

    Check out the FAQ, it's covered there.


Log in to reply
 

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