两个指针
文章平均质量分 71
nicaishibiantai
这个作者很懒,什么都没留下…
展开
-
两个指针-sort colors
Given an array with n objectscolored red, white or blue, sort them so that objects of the samecolor are adjacent, with the colors in the order red, white andblue.Here, we will use the integers 0,原创 2014-08-11 11:30:43 · 411 阅读 · 0 评论 -
两个指针-Substring with Concatenation of All Words
public class Solution { public ArrayListfindSubstring(String S, String[] L) { // Start typing your Java solution below // DO NOT write main() function int wordNum = L.leng原创 2014-08-11 11:30:27 · 312 阅读 · 0 评论 -
Remove element
Given an array and a value, remove all instances of that value in place and return the new length.The order of elements can be changed. It doesn't matter what you leave beyond the new length.简单题原创 2015-03-24 02:29:48 · 399 阅读 · 0 评论 -
Longest Substring with At Most Two Distinct Characters
Given a string, find the length of the longest substring T that contains at most 2 distinct characters.For example, Given s = “eceba”,T is "ece" which its length is 3.和minimum window一样的题。一遍过原创 2015-03-26 11:55:27 · 487 阅读 · 0 评论 -
Lintcode - Previous Permutation
Given a list of integers, which denote a permutation.Find the previous permutation in ascending order.NoteThe list may contains duplicate integers.ExampleFor [1,3,2,3], the pre原创 2015-02-13 15:21:52 · 4822 阅读 · 0 评论 -
Lintcode - Sort Letters by Case
Given a string which contains only letters. Sort it by lower case first and upper case second.NoteIt's not necessary to keep the original order of lower-case letters and upper case letters.原创 2015-02-08 07:16:17 · 1981 阅读 · 0 评论 -
Lintcode - Median
Given a unsorted array with integers, find the median of it. A median is the middle number of the array after it is sorted. If there are even numbers in the array, return the N/2-th number aft原创 2015-02-05 15:51:05 · 3589 阅读 · 0 评论 -
Lintcode - Interleaving Positive and Negative Numbers
Given an array with positive and negative integers. Re-range it to interleaving with positive and negative integers.You are not necessary to keep the original order or positive integers or negat原创 2015-02-03 13:02:45 · 2357 阅读 · 0 评论 -
各种3sum 4sum
这两天做了3sum, 3sum closest, 4sum一个模板就是先sort array, 取一个或两个下标(depend on 3sum or 4sum)然后用另外两个指针指向头和尾。由于数组已经排序,只需要这两个指针扫一遍。教训:当sum == target时,经常忘记移动两个下标(k,l),使得死循环或者不再去判断k+1到l-1之间的数组。public class So原创 2014-08-11 11:30:38 · 432 阅读 · 0 评论 -
Lintcode - sort colors II
Given an array of n objects with k different colors (numbered from 1 to k), sort them so that objects of the same color are adjacent, with the colors in the order 1, 2, ... k.NoteYou are not s原创 2015-01-30 14:02:34 · 3454 阅读 · 1 评论 -
Valid Number
public boolean isNumber(String s) { int start = 0; while (start < s.length() && s.charAt(start) == ' ') { start++; } if (start < s.length() && (s.charAt(sta原创 2014-09-22 06:49:22 · 331 阅读 · 0 评论 -
Remove Duplicates from Sorted Array
Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this in place with原创 2014-10-13 06:35:34 · 312 阅读 · 0 评论 -
Remove Duplicates from Sorted Array II
Follow up for "Remove Duplicates":What if duplicates are allowed at most twice?For example,Given sorted array A = [1,1,1,2,2,3],Your function should return length = 5, and A is now [1,1,2,原创 2014-10-13 06:55:16 · 300 阅读 · 0 评论 -
Minimum Window Substring
Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).For example,S = "ADOBECODEBANC"T = "ABC"Minimum window is "BAN原创 2014-09-11 12:44:36 · 411 阅读 · 0 评论 -
两个指针-3sum, 3sum closes
Time complexity O(n^2) public intthreeSumClosest(int[] num, int target) { // Start typing your Java solution below // DO NOT write main() function Arrays.sort(num);原创 2014-08-11 11:30:25 · 367 阅读 · 0 评论 -
两个指针-partition list
2014.7.26 update: public ListNodepartition(ListNode head, int x) { ListNode fakeLeftHead = new ListNode(0); ListNode fakeRightHead = new ListNode(0); ListNode leftTail =原创 2014-08-11 11:30:30 · 431 阅读 · 0 评论 -
Merge k Sorted Lists
方法一就是俩俩merge:1.1:采用iterate的方法决定mergenaliangpublic class Solution { public ListNode mergeKLists(List lists) { if (lists.isEmpty()) { return null; }原创 2014-08-25 07:06:22 · 336 阅读 · 0 评论 -
Minimum size subarray sum
iven an array of n positive integers and a positive integer s, find the minimal length of a subarray of which the sum ≥ s. If there isn't one, return 0 instead.For example, given the array [2,3,原创 2015-05-18 06:15:08 · 912 阅读 · 0 评论