
Two Pointers
文章平均质量分 72
豆腐脑是咸的
这个作者很懒,什么都没留下…
展开
-
Implement strStr() (Java)
Implement strStr(). Returns a pointer to the first occurrence of needle in haystack, or null if needle is not part of haystack. 注意 " "原创 2014-10-28 13:12:33 · 346 阅读 · 0 评论 -
Linked List Cycle II (Java)
Given a linked list, return the node where the cycle begins. If there is no cycle, return null. Follow up: Can you solve it without using extra space? 先用一个指针走一步,另一个指针走两步的方法判断是否存在回路,如果存在,则将其中一个指原创 2015-01-01 21:20:35 · 334 阅读 · 0 评论 -
Remove Duplicates from Sorted Array II (Java)
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,原创 2015-01-03 16:22:09 · 424 阅读 · 0 评论 -
Longest Substring Without Repeating Characters (Java)
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. Fo原创 2015-01-03 20:23:40 · 291 阅读 · 0 评论 -
3Sum Closest (Java)
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 exact原创 2015-01-04 14:39:38 · 428 阅读 · 0 评论 -
3Sum (Java)
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原创 2015-01-04 13:33:18 · 440 阅读 · 0 评论 -
4Sum (Java)
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: Element原创 2015-01-04 15:51:27 · 818 阅读 · 0 评论 -
Trapping Rain Water (Java)
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-01-24 11:50:33 · 333 阅读 · 0 评论 -
Linked List Cycle (Java)
Given a linked list, determine if it has a cycle in it. Follow up: Can you solve it without using extra space? 设两个指针,一个走两步,一个走一步,如果有环,快的一定会和慢的汇合 Source /** * Definition for singly-linked原创 2015-01-01 20:46:45 · 316 阅读 · 0 评论 -
Container With Most Water (Java)
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). Fin原创 2015-01-03 21:21:57 · 294 阅读 · 0 评论 -
Remove Nth Node From End of List (Java)
Given a linked list, remove the nth node from the end of list and return its head. For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the原创 2014-10-27 21:36:56 · 317 阅读 · 0 评论 -
Merge Sorted Array (Java)
Given two sorted integer arrays A and B, merge B into A as one sorted array. Note: You may assume that A has enough space (size that is greater or equal to m + n) to hold additional elements f原创 2014-12-25 17:47:59 · 391 阅读 · 0 评论 -
Valid Palindrome (Java)
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. For example, "A man, a plan, a canal: Panama" is a palindrome. "race a car" is not a原创 2014-12-23 10:31:29 · 337 阅读 · 0 评论 -
Rotate List (Java)
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. 注意:这题是rotate 就像是把链表首尾相连,然后向右翻转,所以原创 2015-01-01 15:47:41 · 435 阅读 · 0 评论 -
Partition List (Java)
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-01-01 20:32:18 · 501 阅读 · 0 评论 -
Remove Duplicates from Sorted Array (Java)
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-28 10:34:37 · 464 阅读 · 0 评论 -
Sort Colors (Java)
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-01-02 21:39:31 · 326 阅读 · 0 评论 -
Substring with Concatenation of All Words
You are given a string, S, and a list of words, L, that are all of the same length. Find all starting indices of substring(s) in S that is a concatenation of each word in L exactly once and without原创 2015-02-16 13:46:29 · 501 阅读 · 0 评论 -
Remove Element (Java)
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. S原创 2014-10-28 10:20:58 · 417 阅读 · 0 评论