Skip to content

Commit

Permalink
Create: 0160-intersection-of-two-linked-lists.java
Browse files Browse the repository at this point in the history
  • Loading branch information
laitooo committed Jan 4, 2023
1 parent e5730f0 commit 06a9526
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions java/0160-intersection-of-two-linked-lists.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) {
* val = x;
* next = null;
* }
* }
*/
public class Solution {
public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
ListNode a = headA, b = headB;
while (a != b) {
a = (a != null) ? a.next : headB;
b = (b != null) ? b.next : headA;
}
return a;
}
}

0 comments on commit 06a9526

Please sign in to comment.