> For the complete documentation index, see [llms.txt](https://shangan.gitbook.io/algorithm/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://shangan.gitbook.io/algorithm/he-xin-suan-fa-200-ti/linkedlist/intersection-of-two-linked-lists.md).

# Intersection of Two Linked Lists

{% tabs %}
{% tab title="Java" %}

```java
public class Solution {
		public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
			if (headA == null || headB == null) return null;
			ListNode tempA = headA;
			ListNode tempB = headB;
			int loopTime = 0;
			while (loopTime != 2) {
				if (tempA == null) {
					loopTime++;
					tempA = headB;
				}
				if (tempB == null) {
					tempB = headA;
				}
				if (tempA == tempB) return tempA;
				tempA = tempA.next;
				tempB = tempB.next;
			}
			return null;
		}
}

```

{% endtab %}
{% endtabs %}
