摘要: https://leetcode.com/problems/reorder-list/description/Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes' values.... 阅读全文
posted @ 2018-02-25 23:51 davidnyc 阅读(118) 评论(0) 推荐(0)
摘要: 取中点: 翻转: 合并: 插入:使用DUMMY head 避免了头部不确定, 头部为空等各种情况 阅读全文
posted @ 2018-02-25 12:25 davidnyc 阅读(279) 评论(0) 推荐(0)
摘要: https://leetcode.com/problems/find-peak-element/description/A peak element is an element that is greater than its neighbors.Given an input array where num[i] ≠ num[i+1], find a peak element and return... 阅读全文
posted @ 2018-02-25 11:56 davidnyc 阅读(92) 评论(0) 推荐(0)
摘要: 这个笨方法也能通过 阅读全文
posted @ 2018-02-25 11:21 davidnyc 阅读(125) 评论(0) 推荐(0)
摘要: 与Find Minimum in Rotated Sorted Array类似。因为rotate, 所以不能直接用Binary Search, 需要进行 二次判定。 case 1: nums[mid] == target, return mid. case 2: nums[mid] < nums[r 阅读全文
posted @ 2018-02-25 09:49 davidnyc 阅读(137) 评论(0) 推荐(0)
摘要: Given a 2D matrix that contains integers only, which each row is sorted in an ascending order. The first element of next row is larger than (or equal 阅读全文
posted @ 2018-02-25 04:34 davidnyc 阅读(227) 评论(0) 推荐(0)
摘要: Given a target integer T and an integer array A sorted in ascending order, find the index i in A such that A[i] is closest to T. Assumptions There can 阅读全文
posted @ 2018-02-25 03:53 davidnyc 阅读(184) 评论(0) 推荐(0)
摘要: Given a target integer T and an integer array A sorted in ascending order, find the index of the last occurrence of T in A or return -1 if there is no 阅读全文
posted @ 2018-02-25 00:18 davidnyc 阅读(207) 评论(0) 推荐(0)
摘要: Given a target integer T and an integer array A sorted in ascending order, find the index of the first occurrence of T in A or return -1 if there is n 阅读全文
posted @ 2018-02-25 00:08 davidnyc 阅读(211) 评论(0) 推荐(0)