Skip to content

Commit 870f113

Browse files
committed
Time: 1 ms (99.92%), Space: 48.6 MB (62.92%) - LeetHub
1 parent 89ae6e0 commit 870f113

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Definition for singly-linked list.
3+
* public class ListNode {
4+
* int val;
5+
* ListNode next;
6+
* ListNode(int x) {
7+
* val = x;
8+
* next = null;
9+
* }
10+
* }
11+
*/
12+
public class Solution {
13+
public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
14+
if(headA == null || headB == null) return null;
15+
16+
ListNode a = headA;
17+
ListNode b = headB;
18+
19+
while( a != b){
20+
a = a == null? headB : a.next;
21+
b = b == null? headA : b.next;
22+
}
23+
return a;
24+
}
25+
}

0 commit comments

Comments
 (0)