IncredibleThings

导航

上一页 1 ··· 11 12 13 14 15 16 17 18 19 ··· 28 下一页

2018年7月10日 #

LeetCode - One Edit Distance

摘要: 1. 两个字符串的长度之差大于1,那么直接返回False 2. 两个字符串的长度之差等于1,那么长的那个字符串去掉一个字符,剩下的应该和短的字符串相同 3. 两个字符串的长度之差等于0,那么两个字符串对应位置的字符只能有一处不同。 阅读全文

posted @ 2018-07-10 10:42 IncredibleThings 阅读(102) 评论(0) 推荐(0)

2018年7月8日 #

LeetCode-House Robber

摘要: 用递归来做会有time limited error: 阅读全文

posted @ 2018-07-08 22:05 IncredibleThings 阅读(91) 评论(0) 推荐(0)

2018年7月3日 #

LeetCode-Scramble String

摘要: 简单的说,就是s1和s2是scramble的话,那么必然存在一个在s1上的长度l1,将s1分成s11和s12两段,同样有s21和s22。那么要么s11和s21是scramble的并且s12和s22是scramble的;要么s11和s22是scramble的并且s12和s21是scramble的。 两 阅读全文

posted @ 2018-07-03 11:02 IncredibleThings 阅读(95) 评论(0) 推荐(0)

2018年7月2日 #

LeetCode-Integer to English Words

摘要: 分成了三种状态。 0-19 20,30,40,...90 thousand, million, billion 所以,给一个三位数,如何转换成英语,这个是核心功能。 于是就用几个数组。 注意的地方是: else if (num < 100) { return TENS[num / 10] + " " 阅读全文

posted @ 2018-07-02 07:11 IncredibleThings 阅读(105) 评论(0) 推荐(0)

LeetCode-Remove Invalid Parentheses

摘要: 看到parenthese的问题,第一反应是用栈。这题要求minimum number,所以想到用BFS遍历解空间树。 思路为: 层次依次为删除0个元素,1个元素,2个元素。。。 层次遍历所有的可能。如果有一种可能是valid,那么不再遍历下面的层。 阅读全文

posted @ 2018-07-02 06:08 IncredibleThings 阅读(145) 评论(0) 推荐(0)

LeetCode-Moving Average from Data Stream

摘要: 这道题目让我们设计一个移动平均值的结构,我们有一个input size, 这个size是控制着我们的window。每次都新的数字进来,如果目前的size小于window,那么继续加入。如果新的数字进来,size已经满了,等于window size。那么我们需要把第一个数字去除,然后加入新的数字。可以 阅读全文

posted @ 2018-07-02 04:23 IncredibleThings 阅读(121) 评论(0) 推荐(0)

LeetCode-Sliding Window Maximum

摘要: 大概思路是用双向队列保存数字的下标,遍历整个数组,如果此时队列的首元素是i - k的话,表示此时窗口向右移了一步,则移除队首元素。然后比较队尾元素和将要进来的值,如果小的话就都移除,然后此时我们把队首元素加入结果中即可 阅读全文

posted @ 2018-07-02 03:39 IncredibleThings 阅读(120) 评论(0) 推荐(0)

2018年6月10日 #

LeetCode - Nth Digit

摘要: 是说自然数序列看成一个长字符串,问我们第N位上的数字是什么。那么这道题的关键就是要找出第N位所在的数字,然后可以把数字转为字符串,这样直接可以访问任何一位。那么我们首先来分析自然数序列和其位数的关系,前九个数都是1位的,然后10到99总共90个数字都是两位的,100到999这900个数都是三位的,那 阅读全文

posted @ 2018-06-10 05:34 IncredibleThings 阅读(113) 评论(0) 推荐(0)

2018年6月6日 #

LeetCode – Number of Islands II

摘要: A 2d grid map of m rows and n columns is initially filled with water. We may perform an addLand operation which turns the water at position (row, col) 阅读全文

posted @ 2018-06-06 10:13 IncredibleThings 阅读(138) 评论(0) 推荐(0)

LeetCode – Number of Islands

摘要: The basic idea of the following solution is merging adjacent lands, and the merging should be done recursively. 1. DFS 二刷: 注意在变‘1’为‘2’的时候要判断当前值是否为‘1’用 阅读全文

posted @ 2018-06-06 09:42 IncredibleThings 阅读(108) 评论(0) 推荐(0)

上一页 1 ··· 11 12 13 14 15 16 17 18 19 ··· 28 下一页