IncredibleThings

导航

2016年5月3日 #

LeetCode-Remove Duplicates from Sorted Array

摘要: 注意边界case 阅读全文

posted @ 2016-05-03 02:14 IncredibleThings 阅读(108) 评论(0) 推荐(0) 编辑

LeetCode-Swap Nodes in Pairs

摘要: 这道题考验链表的遍历, 切记要加上一个dummy head, 并且区分index的单偶数,不难 阅读全文

posted @ 2016-05-03 01:37 IncredibleThings 阅读(108) 评论(0) 推荐(0) 编辑

2016年4月30日 #

LeetCode-Merge Two Sorted Lists

摘要: Analysis The key to solve the problem is defining a fake head. Then compare the first elements from each list. Add the smaller one to the merged list. 阅读全文

posted @ 2016-04-30 00:08 IncredibleThings 阅读(115) 评论(0) 推荐(0) 编辑

2016年4月29日 #

LeetCode-Valid Parentheses

摘要: 这一题是典型的使用压栈的方式解决的问题,题目中还有一种valid情况没有说明,需要我们自己考虑的,就是"({[]})"这种层层嵌套但 可以完全匹配的,也是valid的一种。解题思路是这样的:我们对字符串S中的每一个字符C,如果C不是右括号,就压入栈stack中。 如果C是右括号,判断stack是不是 阅读全文

posted @ 2016-04-29 23:00 IncredibleThings 阅读(148) 评论(0) 推荐(0) 编辑

LeetCode-Remove Nth Node From End of List

摘要: 经典题。双指针,一个指针先走n步,然后两个同步走,直到第一个走到终点,第二个指针就是需要删除的节点。唯一要注意的就是头节点的处理,比如,1->2->NULL, n =2; 这时,要删除的就是头节点。 阅读全文

posted @ 2016-04-29 04:47 IncredibleThings 阅读(101) 评论(0) 推荐(0) 编辑

2016年4月5日 #

LeetCode-Longest Common Prefix

摘要: Write a function to find the longest common prefix string amongst an array of strings. public class Solution { public String longestCommonPrefix(String[] strs) { if(strs==null && strs.lengt... 阅读全文

posted @ 2016-04-05 05:59 IncredibleThings 阅读(141) 评论(0) 推荐(0) 编辑

2016年3月30日 #

LeetCode-Integer to Roman

摘要: 思路:这题需要一些背景知识,首先要知道罗马数字是怎么表示的:http://en.wikipedia.org/wiki/Roman_numeralsI: 1V: 5X: 10L: 50C: 100D: 500M: 1000字母可以重复,但不超过三次,当需要超过三次时,用与下一位的组合表示:I: 1, 阅读全文

posted @ 2016-03-30 22:42 IncredibleThings 阅读(150) 评论(0) 推荐(0) 编辑

2016年3月23日 #

LeetCode-Container With Most Water

摘要: 合理性解释:当左端线段L小于右端线段R时,我们把L右移,这时舍弃的是L与右端其他线段(R-1, R-2, ...)组成的木桶,这些木桶是没必要判断的,因为这些木桶的容积肯定都没有L和R组成的木桶容积大。 阅读全文

posted @ 2016-03-23 01:10 IncredibleThings 阅读(148) 评论(0) 推荐(0) 编辑

2016年3月11日 #

LeetCode-Increasing Triplet Subsequence

摘要: 解此题可以创造出两个变量用于维护最小和此小的值, 遍历数组中, 如果有比这两个变量都大的数,返回true,否则返回false。 可以维护一个当前的长度为2的升序序列(小的值叫small, 大的叫big),如果碰到比第二个值大的说明可以找到升序的三个值。并且在过程中不断更新small和big的值,使得 阅读全文

posted @ 2016-03-11 06:55 IncredibleThings 阅读(180) 评论(0) 推荐(0) 编辑

2016年3月10日 #

LeetCode-Self Crossing

摘要: You are given an array x of n positive numbers. You start at point (0,0) and moves x[0] metres to the north, then x[1] metres to the west, x[2] metres 阅读全文

posted @ 2016-03-10 01:57 IncredibleThings 阅读(207) 评论(0) 推荐(0) 编辑