Two Pointers
文章平均质量分 71
dyllanzhou
这个作者很懒,什么都没留下…
展开
-
[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 0,原创 2015-09-25 15:03:33 · 279 阅读 · 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]原创 2016-01-05 10:19:10 · 302 阅读 · 0 评论 -
[Leetcode]Find the Duplicate Number
Given an array nums containing n + 1 integers where each integer is between 1 andn (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate number, f原创 2015-12-01 15:37:38 · 259 阅读 · 0 评论 -
[Leetcode]Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. For原创 2015-11-14 16:57:23 · 240 阅读 · 0 评论 -
[Leetcode] Linked List Cycle
Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?class Solution {public: /*algorithm: hash solution time O(n) space O(n)原创 2015-09-16 11:09:06 · 283 阅读 · 0 评论 -
[Leetcode]Rotate List
Given a list, rotate the list to the right by k places, where k is non-negative.For example:Given 1->2->3->4->5->NULL and k = 2,return 4->5->1->2->3->NULL./** * Definition for singly-linked l原创 2015-11-11 21:43:49 · 211 阅读 · 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-10-25 22:54:36 · 355 阅读 · 0 评论 -
[Leetcode]3Sum
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) m原创 2015-11-10 11:05:58 · 169 阅读 · 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 that satisfy the condition nums[i] + nums[j] + nums[k] .For example, given nums = [-2, 0, 1, 3原创 2015-10-25 22:59:38 · 426 阅读 · 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原创 2015-11-10 11:08:54 · 270 阅读 · 0 评论 -
[Leetcode]Partition List
Given a linked list and a value x, partition it such that all nodes less thanx come before nodes greater than or equal to x.You should preserve the original relative order of the nodes in each of原创 2015-10-23 12:51:10 · 263 阅读 · 0 评论 -
[Leetcode]Linked List Cycle II
Given a linked list, return the node where the cycle begins. If there is no cycle, returnnull.Note: Do not modify the linked list.Follow up:Can you solve it without using extra space?/**原创 2015-10-08 15:00:09 · 206 阅读 · 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 linei is at (i, ai) and (i, 0). Find原创 2015-10-04 23:27:32 · 253 阅读 · 0 评论 -
[Leetcode]Reverse Vowels of a String
Write a function that takes a string as input and reverse only the vowels of a string.Example 1:Given s = "hello", return "holle".Example 2:Given s = "leetcode", return "leotcede".Subscrib原创 2016-06-23 15:04:16 · 216 阅读 · 0 评论