Given a sorted linked list, delete all duplicates such that each element appear only once.
For example,
Given 1->1->2, return 1->2.
Given 1->1->2->3->3, return 1->2->3.
/**
* Definition for sin...
分类:
其他好文 时间:
2015-01-13 16:07:31
阅读次数:
212
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.
For example,
Given 1->2->3->3->4->4->5, return 1->2->5.
Given 1->1-...
分类:
其他好文 时间:
2015-01-13 16:00:02
阅读次数:
137
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...
分类:
其他好文 时间:
2015-01-09 09:17:50
阅读次数:
165
双指针思想,尾指针不断往后扫,当扫到有一个窗口包含了所有T的字符,然后再收缩头指针,直到不能再收缩为止。最后记录所有可能的情况中窗口最小的...
原题链接:https://oj.leetcode.com/problems/two-sum/
撇开暴力破解,这道题有众所周知的两种做法:
1. 先排序,再一前一尾双指针。这种方法要注意的是,排序时需要保存原来的index,这样的话其实是一个有着value和index的结构体基于value的排序。
2. 直接hash。这道题需要注意的是,如果数组有两个相同元素,但是仍然构成唯一解。比如...
分类:
其他好文 时间:
2015-01-05 14:54:31
阅读次数:
190
Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?使用双指针fast和slow,fast每次走两步,slow每次走一步,如果fast追...
分类:
其他好文 时间:
2014-12-03 23:04:47
阅读次数:
287
这个方法其实 蛮常用的一般给你3个集合 然后让你满足某个等式 a[x]+b[y] = c[z]我们通常都是枚举一个集合 然后用两个指针分别指向另外2个集合中的一头一尾 然后进行大小比较来 指针移动当然 这也是和 二分一样建立在 有序的基础之上进行的这题 用这个方法解决 就可以了当然 二分也可以 1 ...
分类:
其他好文 时间:
2014-11-27 20:12:49
阅读次数:
198
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?
这个题目跟Linked List Cycle一样,我也没有能够自己独立找到解决方法,...
分类:
其他好文 时间:
2014-11-26 18:57:10
阅读次数:
126
使用双指针,i遍历全部字符,start收集重复的次数,最后不重复出现的字符个数maxx为i-start+1;// main.cpp// Longest Substring//// Created by Bowie Hsu on 14/11/21.// Copyright (c) 2014年 Bowi...
分类:
其他好文 时间:
2014-11-24 13:21:59
阅读次数:
142
Linked List CycleGiven a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?这道题要用双指针,但我想试一下投机取巧的办法行不行...
分类:
其他好文 时间:
2014-11-20 21:46:01
阅读次数:
185