115 Distinct Subsequences

2017-04-02
阅读 1 分钟
1.6k
{代码...} {代码...} {代码...}

97 Interleaving String

2017-04-02
阅读 2 分钟
2.1k
{代码...} 和edit distance一样给出dp和memorized search两种方法。memorized search速度更快。 {代码...} {代码...}

10 Regular Expression Matching, 填dp table

2017-04-02
阅读 2 分钟
2.3k
Implement regular expression matching with support for '.' and '*'. {代码...} {代码...} {代码...}

72 Edit Distance 以及两个string比较的填表通解。

2017-04-02
阅读 3 分钟
2k
72 Edit Distance {代码...} {代码...} {代码...} {代码...}

355. Design Twitter , 用23. Merge k Sorted Lists和OOD思想解答。

2017-04-02
阅读 5 分钟
2.5k
Merge k Sorted Lists {代码...} {代码...} {代码...} {代码...}

leetcode 341 Flatten Nested List Iterator 以及其他Iterator合集

2017-04-02
阅读 4 分钟
3.4k
Zigzag Iterator这个题目和merge k sorted list很像,design twitter用到的就是merge k sorted list的思想加上OOD,会另写一篇。

273. Integer to English Words

2017-04-01
阅读 2 分钟
3.2k
这样穷举出所有情况的好处,就是不用处理IV这种特殊情况,变得更迅速高效,代码也简洁。相当于简化版的Integer to English Words.

5. Longest Palindromic Substring

2017-04-01
阅读 2 分钟
1.5k
{代码...} {代码...} {代码...} {代码...}

336. Palindrome Pairs

2017-04-01
阅读 3 分钟
4.1k
{代码...} {代码...} {代码...}

131. Palindrome Partitioning and 140. Word Break II

2017-03-30
阅读 3 分钟
2k
{代码...} {代码...} {代码...} {代码...}

LC 267 Palindrome Permutation II

2017-03-30
阅读 2 分钟
3.8k
{代码...} {代码...}

425 Word Squares

2017-02-23
阅读 3 分钟
3.1k
在给定的词典里,找到一些单词,组成一个square, 第i行和第i列一样。(0,0) 这个点找到满足条件的,我们选择w。(0,1) 我们要满足wa, a都可以作为开头的部分。(0,2) 我们要满足wal, l都可以作为开头的部分。

leetcode 317 shortest distance from all buildings

2017-02-23
阅读 3 分钟
3.6k
{代码...} 第一个building, 把涂色把0变成-1, 同一层最终会涂成相同颜色-1 {代码...} 距离矩阵 {代码...} 第一个building, 把涂色把-1变成-2, 同一层最终会涂成相同颜色-2 {代码...} 距离矩阵 {代码...} 第一个building, 把涂色把-2变成-3, 同一层最终会涂成相同颜色-3 {代码...} 距离矩阵 {代码...} 为了避路径重复,我...

LFU

2017-02-05
阅读 4 分钟
2k
只个代码由LRU改进得到。如果每一个频率放在一个LRU里面,每个LRU也有头尾两个指针,指向相邻的LRU。实际上相邻的LRU可以由frequency = t+1的第一node,可以由frequency = t的最后一个唯一确认。也就是说,在LRU的设计基础上。我们再多记录一个finalNodes,记录每种频率的尾部就好了。

leetcode 315 Count of Smaller Numbers After Self

2017-02-01
阅读 3 分钟
4k
今天的重头戏 LC315 Count of Smaller Numbers After Self.在讲这个题目之前,请思考这个问题。在BST找到所有比Node P小的节点个数。利用inorder tarvseral我们一直走BST并计数,找到p点就返回计数得到的值。时间复杂度worst case O(n).如果我们要找到的是好多节点的值,如果还用这种方法,时间复杂度就是O(k*n).这里我...

leetcode 315 Count of Smaller Numbers After Self 以及 BST总结。

2017-02-01
阅读 5 分钟
4.3k
BST最明显的特点就是root.left.val < root.val < root.right.val. 还有另一个特点就是,bst inorder traversal result is an ascending array.

132pattern

2017-01-29
阅读 2 分钟
2.5k
Given a sequence of n integers a1, a2, ..., an, a 132 pattern is a subsequence ai, aj, ak such that i < j < k and ai < ak < aj. Design an algorithm that takes a list of n numbers as input and checks whether there is a 132 pattern in the list. Input: [-1, 3, 2, 0]Output: TrueExplanatio...

LC44 wildcard matching

2017-01-26
阅读 3 分钟
1.5k
{代码...} {代码...}

Binary Tree Traversal

2017-01-25
阅读 3 分钟
1.7k
PostOrder {代码...} PreOrder {代码...} InOrder {代码...} PreOrder {代码...} InOrder {代码...}

[leetcode] Minimum Window Substring

2017-01-23
阅读 7 分钟
2.5k
这里聊一聊解一类问题,就是满足某一条件的substring最值问题。最开始我们以Minimum Window Substring为例,并整理总结leetcode里所有类似题目的通解。

permutation i and ii

2017-01-21
阅读 4 分钟
2.4k
Given a collection of distinct numbers, return all possible permutations.[1,2,3][ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1] ]

LRU Cache

2016-12-29
阅读 5 分钟
1.9k
Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set. get(key) - Get the value (will always be positive) of the key if the key exists in the cache, otherwise return -1. set(key, value) - Set or insert the value if the k...

[leetcode]132. Palindrome Partitioning II

2016-12-01
阅读 2 分钟
2.8k
Given a string s, partition s such that every substring of the partition is a palindrome. Return the minimum cuts needed for a palindrome partitioning of s. For example, given s = "aab", Return 1 since the palindrome partitioning ["aa","b"] could be produced using 1 cut.

[leetcode]85. Maximal Rectangle

2016-12-01
阅读 2 分钟
3.6k
Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area.For example, given the following matrix: 1 0 1 0 01 0 1 1 11 1 1 1 11 0 0 1 0 return 6

[leetcode]354. Russian Doll Envelopes

2016-12-01
阅读 2 分钟
2.4k
You have a number of envelopes with widths and heights given as a pair of integers (w, h). One envelope can fit into another if and only if both the width and height of one envelope are greater than the width and height of the other envelope. What is the maximum number of envelopes can you Russia...

[leetcode]Longest Increasing Subsequence

2016-12-01
阅读 2 分钟
1.7k
Given an unsorted array of integers, find the length of longest increasing subsequence. For example, Given [10, 9, 2, 5, 3, 7, 101, 18], The longest increasing subsequence is [2, 3, 7, 101], therefore the length is 4. Note that there may be more than one LIS combination, it is only necessary for ...

[leetcode]174. Dungeon Game

2016-12-01
阅读 3 分钟
2k
The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. The dungeon consists of M x N roomslaid out in a 2D grid. Our valiant knight (K) was initially positioned in the top-left room and must fight his way through the dungeon to rescue the princess. Th...

[leetcode]321. Create Maximum Number

2016-12-01
阅读 2 分钟
2.8k
Given two arrays of length m and n with digits 0-9 representing two numbers. Create the maximum number of length k <= m + n from digits of the two. The relative order of the digits from the same array must be preserved. Return an array of the k digits. You should try to optimize your time and ...

[leetcode] 403. Frog Jump

2016-11-30
阅读 3 分钟
5.5k
有点类似于jump game, 只不过这里对步数有了隐形的要求,当前步数和之前步数有关。如果我们用brute force的方法来解,每一步有三种可能,一共n个石头,时间复杂度就是O(3^n)。这其中有很多步数是多余的,第i个石头无法从任何一个石头到达,那么我们应该立即中止搜寻。还有一个石头可能由之前的多个石头到达,这又是可以...

[leetcode]Longest Valid Parentheses

2016-11-30
阅读 2 分钟
1.7k
Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.For "(()", the longest valid parentheses substring is "()", which has length = 2. Another example is ")()())", where the longest valid parentheses substring is "()()...