
Two Pointers
文章平均质量分 65
ljffdream
这个作者很懒,什么都没留下…
展开
-
【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?【分析】使用two pointer的思想,因为如果一个list存在环的话,那个两个pointer必定会相遇!~经过各种改进之后!~写出的原创 2014-12-04 13:40:55 · 332 阅读 · 0 评论 -
[Leetcode]Remove duplicates
[timu]Follow up for "Remove Duplicates":What if duplicates are allowed at most twice?For example,Given sorted array nums = [1,1,1,2,2,3],Your function should return length = 5, with转载 2015-09-02 08:10:54 · 300 阅读 · 0 评论 -
【Leetcode】Reorder List
【题目】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.For example,Given {1,2,3,4}, reorder it转载 2015-08-03 20:21:03 · 280 阅读 · 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.【思路】实质就是n-k个元素挪到了链子的前面, 第原创 2015-07-29 23:06:14 · 261 阅读 · 0 评论 -
【Leetcode】Panlidrome Linked List
【题目】Given a singly linked list, determine if it is a palindrome.Follow up:Could you do it in O(n) time and O(1) space?【思路】panlidrome的话,回文,就是前后是一样的。第一个和最后一个一样, 第二个和倒数第二个一样。linked list转载 2015-07-17 11:27:36 · 332 阅读 · 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转载 2015-06-14 13:02:44 · 290 阅读 · 0 评论 -
[Leetcode]Remove Linked List Elements
[题目]Remove all elements from a linked list of integers that have value val.ExampleGiven: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6Return: 1 --> 2 --> 3 --> 4 --> 5Credits:Special th原创 2015-07-01 09:41:30 · 329 阅读 · 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原创 2015-04-09 01:00:59 · 334 阅读 · 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原创 2014-12-07 10:20:07 · 355 阅读 · 0 评论 -
[Leetcode]sort Color
[timu] Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adja转载 2015-09-02 03:55:21 · 271 阅读 · 0 评论