
Two pointers
iteye_17352
这个作者很懒,什么都没留下…
展开
-
Leetcode - Minumum Size Subarray Sum
Given 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,1...原创 2015-06-09 10:11:44 · 84 阅读 · 0 评论 -
Leetcode - Remove Nth Node From End of List
Remove Nth Node From End of List Total Accepted: 63354 Total Submissions: 234837 My Submissions Question Solution Given a linked list, remove the nth node from the end of list and return its head. ...原创 2015-07-27 21:09:56 · 71 阅读 · 0 评论 -
Leetcode - Remove Elements
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-07-27 10:19:34 · 81 阅读 · 0 评论 -
Leetcode - Minimum Size Subarray Sum
Given 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,1...原创 2015-07-22 21:01:05 · 103 阅读 · 0 评论 -
Leetcode - LinedListCycleII
Given a linked list, return the node where the cycle begins. If there is no cycle, return null. [分析] 这题可以说是快慢指针的经典题。首先判断是否存在环,而后找寻环的入口点。自己的naive思路是从快慢指针相交点处将链表分割成两个新链表,两个新链表的第一个交点即为环的入口点。更优化的思路是参考来...原创 2015-07-22 10:18:34 · 86 阅读 · 0 评论 -
Leetcode - Partition List
Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x. You should preserve the original relative order of the nodes in each of...原创 2015-07-22 09:09:18 · 94 阅读 · 0 评论 -
Leetcode - 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. [分析] 滑动窗口法,窗口内始终仅保留至多两个...原创 2015-07-22 08:32:16 · 102 阅读 · 0 评论 -
Leetcode - 4Sum
Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target. Note: Elements in a...原创 2015-07-21 07:25:46 · 75 阅读 · 0 评论 -
Leetcode - 3Sum Closest
Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exactly...原创 2015-07-20 22:09:46 · 92 阅读 · 0 评论 -
Leetcode - 3 Sum
Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero. Note: Elements in a triplet (a,b,c) must...原创 2015-07-20 21:11:23 · 74 阅读 · 0 评论 -
Leetcode - Container With Most Water
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two ...原创 2015-07-20 09:55:30 · 72 阅读 · 0 评论 -
Leetcode - Trapping Rain Water
Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining. For example, Given [0,1,0,2,1,0,1,3,2,1,2,1]...原创 2015-07-20 09:26:02 · 99 阅读 · 0 评论 -
Leetcode - Sort Colors
Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue. Here, we will use the integers ...原创 2015-07-17 10:04:37 · 145 阅读 · 0 评论 -
Leetcode - Substring with Contentaion of All Words
You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that is a concatenation of each word in words exactly once and wi...原创 2015-06-18 10:01:33 · 90 阅读 · 0 评论 -
Leetcode - Minimum Window String
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 "BANC". ...原创 2015-06-14 19:33:23 · 108 阅读 · 0 评论 -
Leetcode - 3Sum Smaller
Given an array of n integers nums and a target, find the number of index triplets i, j, k with 0原创 2015-08-18 22:12:27 · 96 阅读 · 0 评论