摘要: 题目描述: 唯一的结论是如果数组中所有数的最大公约数为 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) 编辑