上一页 1 ··· 17 18 19 20 21 22 23 24 25 ··· 47 下一页
摘要: 题目描述: 唯一的结论是如果数组中所有数的最大公约数为 1,则存在解,否则不存在。所以只需要计算所有数最大公约数即可,时间复杂度O(nlog(m)),其中 m 为数字大小。 class Solution: def isGoodArray(self, nums: List[int]) -> bool: 阅读全文
posted @ 2019-11-04 14:31 oldby 阅读(108) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 自己的提交: class Solution: def minimumSwap(self, s1: str, s2: str) -> int: count = {"xy":0,"yx":0} for i in range(len(s1)): if s1[i] == s2[i]: conti 阅读全文
posted @ 2019-11-04 14:05 oldby 阅读(279) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 自己的提交:超时: class Solution: def numberOfSubarrays(self, nums, k: int) -> int: dp = [0]* (len(nums)+1) res = 0 for i in range(len(nums)): if nums[i 阅读全文
posted @ 2019-11-04 13:57 oldby 阅读(125) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 自己的提交:O(N) class Solution: def minRemoveToMakeValid(self, s: str) -> str: #from collections import Counter flag = [True] * len(s) stack = [] for 阅读全文
posted @ 2019-11-04 10:56 oldby 阅读(141) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 方法一:暴力O(MN) class Solution: def findSubstring(self, s: str, words: List[str]) -> List[int]: res = [] if not s or not words: return res for j in 阅读全文
posted @ 2019-10-31 15:27 oldby 阅读(136) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 方法一:动态规划 class Solution: def f(self, n, m): if n < m: n, m = m, n if (n, m) in self.mem: return self.mem[(n, m)] if n == m: ans = 1 else: ans = 阅读全文
posted @ 2019-10-28 14:21 oldby 阅读(228) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 自己的提交:O(2**n∗n∗m),m 为字符串长度 class Solution: def maxLength(self, arr: List[str]) -> int: from collections import Counter if not arr:return 0 res = 阅读全文
posted @ 2019-10-28 14:11 oldby 阅读(289) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 参考格雷编码: class Solution: def circularPermutation(self, n: int, start: int) -> List[int]: res = [] for i in range(2 ** n): res.append((i >> 1) ^ i 阅读全文
posted @ 2019-10-28 10:08 oldby 阅读(156) 评论(0) 推荐(0) 编辑
摘要: 题目描述: class Solution: def findSolution(self, customfunction: 'CustomFunction', z: int) -> List[List[int]]: res = [] for i in range(1,1001): for j in r 阅读全文
posted @ 2019-10-28 10:01 oldby 阅读(164) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 方法:动态规划: 自底向上: class Solution: def minDistance(self, word1: str, word2: str) -> int: n = len(word1) m = len(word2) dp = [[0 for _ in range(n+1)] 阅读全文
posted @ 2019-10-26 16:44 oldby 阅读(101) 评论(0) 推荐(0) 编辑
上一页 1 ··· 17 18 19 20 21 22 23 24 25 ··· 47 下一页