@@ -0,0 +1,2236 @@
+package leetcode;%0A%0A/**%0A * https://oj.leetcode.com/problems/intersection-of-two-linked-lists/%0A */%0Apublic class Problem160 %7B%0A    public static class ListNode %7B%0A        int val;%0A        ListNode next;%0A%0A        ListNode(int x) %7B%0A            val = x;%0A            next = null;%0A        %7D%0A    %7D%0A%0A    public ListNode getIntersectionNode(ListNode headA, ListNode headB) %7B%0A        int sizeA = 0;%0A        for (ListNode n = headA; n != null; n = n.next) %7B%0A            sizeA++;%0A        %7D%0A        int sizeB = 0;%0A        for (ListNode n = headB; n != null; n = n.next) %7B%0A            sizeB++;%0A        %7D%0A        int diff = Math.abs(sizeA - sizeB);%0A        ListNode nodeA = headA;%0A        ListNode nodeB = headB;%0A        if (sizeA %3E sizeB) %7B%0A            for (int i = 0; i %3C diff; i++) %7B%0A                nodeA = nodeA.next;%0A            %7D%0A        %7D else if (sizeA %3C sizeB) %7B%0A            for (int i = 0; i %3C diff; i++) %7B%0A                nodeB = nodeB.next;%0A            %7D%0A        %7D%0A        for (ListNode a = nodeA, b = nodeB; a != null %7C%7C b != null; a = a.next, b = b.next) %7B%0A            if (a == b) %7B%0A                return a;%0A            %7D%0A        %7D%0A        return null;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        Problem160 prob = new Problem160();%0A        %0A        ListNode intersection = new ListNode(3);%0A        intersection.next = new ListNode(4);%0A        intersection.next.next = new ListNode(5);%0A        %0A        ListNode list1 = new ListNode(1);%0A        list1.next = new ListNode(2);%0A        list1.next.next = intersection;%0A        %0A        for (ListNode n = list1; n != null; n = n.next) %7B%0A            System.out.print(n.val + %22 %22);%0A        %7D%0A        System.out.println();%0A        %0A        ListNode list2 = new ListNode(100);%0A        list2.next = new ListNode(200);%0A        list2.next.next = new ListNode(300);%0A        list2.next.next.next = intersection;%0A        %0A        for (ListNode n = list2; n != null; n = n.next) %7B%0A            System.out.print(n.val + %22 %22);%0A        %7D%0A        System.out.println();%0A        %0A        ListNode result = prob.getIntersectionNode(list1, list2);%0A        for (ListNode n = result; n != null; n = n.next) %7B%0A            System.out.print(n.val + %22 %22);%0A        %7D%0A        System.out.println();%0A    %7D%0A%7D%0A

Solve problem 160