Share my Java code


  • -3
    Y
    public class Solution {
    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        if(headA==null||headB==null){
    		return null;
    	}
    	while(headA!=null&&headB!=null){
    		if(headA.val<headB.val){
    			headA=headA.next;
    		}
    		else if(headA.val>headB.val) headB=headB.next;
    		else{
    			return headA;
    		}	
    	}
    	return null;
    }
    

    }


  • 3
    C

    This is not a good solution as the question does not specify the property of the values. Therefore we cannot use the values based on any assumption. In case the values are not sorted or even not comparable, this algorithm will fail.


  • 0
    Y

    but, how come it accepted?


  • 0
    V

    it must be defects of test cases


Log in to reply
 

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