leetcode
xixi up!
这个作者很懒,什么都没留下…
展开
-
leetcode四道组合总和题目的DP求解(39+40+216+377)
这四道题目相似,只是有不同的区别,这里记录一下这四道题目的DP解法。leetcode39:Given a set of candidate numbers (candidates) (without duplicates) and a target number (target), find all unique combinations in candidates where the candidate numbers sums to target.The same repeated number m原创 2020-07-03 21:01:31 · 259 阅读 · 0 评论 -
leetcode32 最长有效括号
题目:Given a string containing just the characters ‘(’ and ‘)’, find the length of the longest valid (well-formed) parentheses substring.Example 1:Input: “(()”Output: 2Explanation: The longest valid parentheses substring is “()”Example 2:Input: “)()()原创 2020-06-30 23:40:23 · 191 阅读 · 0 评论 -
leetcode31下一个更大的排列
题目: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 lowest possible order (ie, sorted in ascending order).The replacement原创 2020-06-30 11:19:40 · 262 阅读 · 0 评论 -
leetcode567. Permutation in String
**题目:Given two strings s1 and s2, write a function to return true if s2 contains the permutation of s1. In other words, one of the first string’s permutations is the substring of the second string.Example 1:Input: s1 = “ab” s2 = “eidbaooo”Output: TrueE原创 2020-06-29 18:04:18 · 191 阅读 · 0 评论 -
leetcode30 Substring with Concatenation of All Words
You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that is a concatenation of each word in words exactly once and without any intervening characters.Example 1:Input:s =原创 2020-06-29 16:37:31 · 115 阅读 · 0 评论 -
leetcode15三数之和、16三数最接近之和、18四数之和总结
这一类的问题相似,只不过是具体个数上有所区别。很自然的一种思路就是暴力破解法,然而这种方法的时间复杂度太高,若为K数之和,时间复杂度可以达到O(nk)。还有一种方法就是采用双指针法,也就是先固定好k-2个数,然后将剩下两个数采用双指针法进行选择。这样前面k-2个位置的选则复杂度为O(nk-2),再算上后面的双指针,总共的时间复杂度也就是O(nk-1),(这时间复杂度也挺高的…)。下面是具体的题目及代码。3SumGiven an array nums of n integers, are there e原创 2020-06-27 16:41:31 · 159 阅读 · 0 评论