- 浏览: 201067 次
- 性别:
- 来自: 杭州
最新评论
-
hthhit:
...
回溯算法之N皇后问题(java实现) -
huntfor:
249326109 写道这个算法的复杂度有考虑过么O(n^2) ...
[leetcode]Longest Valid Parentheses -
249326109:
这个算法的复杂度有考虑过么
[leetcode]Longest Valid Parentheses -
huntfor:
249326109 写道又搜到你的了 你怎么搜的,为啥我搜不到 ...
[leetcode]Sort Colors -
249326109:
又搜到你的了
[leetcode]Sort Colors
文章列表
新博文地址:
[leetcode]Palindrome Partitioning II
Palindrome Partitioning II
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 si ...
dfs过得太蹊跷了,本博文算法作废,新博文地址:[leetcode]Surrounded Regions
Surrounded Regions
Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'.A region is captured by flipping all 'O's into 'X's in that surrounded region.For example,X X X XX O O XX X O XX O X XAfter running your funct ...
新博文地址:[leetcode]Longest Valid Parentheses
Longest Valid Parentheses
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 ...
本博文的方法有点投机取巧了,新博文中采取了更通用的解法,新博文地址:[leecode]Word Break II
Word Break II
Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid dictionary word.Return all such possible sentences.For example, givens = "catsanddog",dict = ...
新博文地址:[leetcode]Word Break
Word Break
Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words.For example, givens = "leetcode",dict = ["leet", "code"].Return true because &qu ...
Word Ladder
Given two words (start and end), and a dictionary, find the length of shortest transformation sequence from start to end, such that:Only one letter can be changed at a timeEach intermediate word must exist in the dictionaryFor example,Given:start = "hit"end = "cog"di ...
新博文地址:[leetcode]Distinct Subsequences
Distinct Subsequences
Given a string S and a string T, count the number of distinct subsequences of T in S.A subsequence of a string is a new string which is formed from the original string by deleting some (can be none) of the characters without disturbing t ...
算法还是一样的算法,但是新博文的代码更简洁,可读性更好,新博文地址:[leetcode]Permutation Sequence
Permutation Sequence
The set [1,2,3,…,n] contains a total of n! unique permutations.By listing and labeling all of the permutations in order,We get the following sequence (ie, for n = 3):"123""132""213" ...
新博文地址:[leetcode]PermutationsII
Permutations II
Given a collection of numbers that might contain duplicates, return all possible unique permutations.For example,[1,1,2] have the following unique permutations:[1,1,2], [1,2,1], and [2,1,1].
排列的题应该是很熟悉的,不熟悉的可以看这几道题:Permutations,Next Permutation, 其 ...
怎么说呢,这篇博文的算法还是很不错的,新博文采用的还是这篇博文的就算法,只不过代码更简洁,可能读可能更好一点,有兴趣请移步,新博文地址:[leetcode]Next Permutation
Next Permutation
Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowe ...
新博文地址:[leetcode]Decode Ways
Decode Ways
写道
A message containing letters from A-Z is being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, determine the total number of ways to decode it.For example,Gi ...
新博文地址:[leetcode]Divide Two Integers
Divide Two Integers
Divide two integers without using multiplication, division and mod operator.
不使用 乘法、除法、取余来计算除法,这道题在很多书中都有提及,比如面试金典中就有一道题要求只用加法来计算:减法、乘法、除法。其中它对除法的算法思想是,用迭代一个一个加被除数,直到》dividend,但是这无疑是个坑,比如当divideng = Integer.MAX_VALUE;divisor =1;必定会超时。
...
新博文地址:
[leetcode]Combination SumII
Combination Sum II
Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.Each number in C may only be used once in the combination.Note:All numbers (including target) will be ...
新博文地址:[leetcode]Anagrams
Anagrams
Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.
这道题我没看懂啥意思,看了解释之后才知道是从给定的数组中挑出互为anagram的单词,这道题曾经在编程珠玑上看到过,因此没多做考虑就直接开始编码了
具体算法思想是:
对每个单词做出标记,例如对于anagram标记为a3g1m1n1r1,表示这个单词有3个a,1个g等等。
第一遍遍历数组 ...
新博文地址:[leetcode]Edit distance
Edit Distance
Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)You have the following 3 operations permitted on a word:a) Insert a characterb) Delete a characterc) ...