diff --git a/160.intersection-of-two-linked-lists.java b/160.intersection-of-two-linked-lists.java new file mode 100644 index 0000000..2754012 --- /dev/null +++ b/160.intersection-of-two-linked-lists.java @@ -0,0 +1,59 @@ +/* + * @lc app=leetcode id=160 lang=java + * + * [160] Intersection of Two Linked Lists + */ + +// @lc code=start +/** + * 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) { + if(headA == null || headB == null) { + return null; + } + int la = len(headA), lb = len(headB); + ListNode cura = headA, curb = headB; + if(la < lb) { + // move curB + for(int i=0; i max) { + max = nums[i]; + } + } + return max - min > 2 * k ? max - min - 2 * k : 0; + } +} +// @lc code=end +