public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
		int n = 0, m = 0;
		ListNode a = headA, b = headB;

		while (a != null) {
			a = a.next;
			n++;
		}
		while (b != null) {
			b = b.next;
			m++;
		}

		a = headA;
		b = headB;

		if (n > m) {
			int diff = n - m;
			for (int i = 0; i < diff; i++) {
				a = a.next;
			}
		} else {
			int diff = m - n;
			for (int i = 0; i < diff; i++) {
				b = b.next;
			}
		}

		while (a != null || b != null) {

			if (a.val != b.val) {
				a = a.next;
				b = b.next;
			} else {
				return a;
			}
		}
		return null;
	}