Why this code accepted?It's wrong


  • 0
    D
    public class Solution {
        public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
            ListNode nodeA = headA,nodeB = headB;
            while(nodeA != null && nodeB != null){
                if(nodeA.val > nodeB.val){
                    nodeB = nodeB.next;
                }else if(nodeA.val < nodeB.val){
                    nodeA = nodeA.next;
                } else {
                    return nodeA;
                }
            }
            return null;
        }
    }
    

Log in to reply
 

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