forked from DreamCats/java-notes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGetIntersectionNode.java
More file actions
36 lines (31 loc) · 751 Bytes
/
GetIntersectionNode.java
File metadata and controls
36 lines (31 loc) · 751 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package normal;
/**
* @program JavaBooks
* @description: 160.相交链表
* @author: mf
* @create: 2019/11/05 10:36
*/
/*
题目:https://leetcode-cn.com/problems/intersection-of-two-linked-lists/
难度:easy
类型:链表
*/
/*
A: a1 → a2
↘
c1 → c2 → c3
↗
B: b1 → b2 → b3
*/
public class GetIntersectionNode {
public static void main(String[] args) {
}
public static ListNode getIntersectionNode(ListNode headA, ListNode headB) {
ListNode l1 = headA, l2 = headB;
while (l1 != l2) {
l1 = (l1 == null) ? headB : l1.next;
l2 = (l2 == null) ? headA : l2.next;
}
return l1;
}
}