Skip to content

Commit

Permalink
Merge pull request neetcode-gh#1876 from laitooo/main
Browse files Browse the repository at this point in the history
Create: 0160-intersection-of-two-linked-lists.java
  • Loading branch information
tahsintunan authored Jan 8, 2023
2 parents 42eb54b + 06a9526 commit 8da7688
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 8da7688

Please sign in to comment.