摘要: 按照从小到大的顺序生成递增序列,每生成一个序列,判断是否在限定区间内。 如果超过了区间的上限,则跳过本轮循环(因为后面的值会更大)。 阅读全文
posted @ 2019-12-15 15:29 Sempron2800+ 阅读(137) 评论(0) 推荐(0) 编辑
摘要: 这道题暴力法会TLE,先给出这种TLE方案: 使用前序和方式,Java的可以AC,但是python仍然会TLE,给出这种TLE方案: 参考:https://leetcode.com/problems/maximum-side-length-of-a-square-with-sum-less-than 阅读全文
posted @ 2019-12-15 13:08 Sempron2800+ 阅读(301) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution: 2 def getDecimalValue(self, head: ListNode) -> int: 3 res = 0 4 lists = [] 5 while head != None: 6 lists.append(head.val) 7 head = head.next 8 pos = 0 9 for i in range(len(lists)-1,- 阅读全文
posted @ 2019-12-15 12:58 Sempron2800+ 阅读(152) 评论(0) 推荐(0) 编辑
摘要: 是leetcode1289的基础版本,与leetcode120的思想基本一致。 阅读全文
posted @ 2019-12-15 01:28 Sempron2800+ 阅读(221) 评论(0) 推荐(0) 编辑
摘要: 本题是leetcode 931的升级版,如果直接计算每一行和其上面每一行中不在同一列的和,会TLE。因此只保留上一行最小的2个数字。 在计算当前行时,只需要判断当前单元格的列是否与前一行的最小值在同一列,如果在同一列,则使用倒数第二小的值。否则就使用上一行的最小值。 下面是TLE的方案,可以作为对比 阅读全文
posted @ 2019-12-15 01:26 Sempron2800+ 阅读(168) 评论(0) 推荐(0) 编辑
摘要: 直接调用itertools内置函数,快速生成符合条件的组合。 1286. Iterator for Combination 阅读全文
posted @ 2019-12-15 01:19 Sempron2800+ 阅读(138) 评论(0) 推荐(0) 编辑
摘要: 并查集思想,将可以被合并的(范围小的)区间标记,最后没有标记的就是所求的个数。 另一种思路,先排序再比较,效率更高: 参考:https://leetcode.com/problems/remove-covered-intervals/discuss/451532/Python3-O(n*logn)- 阅读全文
posted @ 2019-12-15 01:17 Sempron2800+ 阅读(147) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution: 2 def findSpecialInteger(self, arr: List[int]) -> int: 3 n = len(arr) 4 dic = {} 5 for i in range(n): 6 if arr[i] not in dic: 7 ... 阅读全文
posted @ 2019-12-15 01:16 Sempron2800+ 阅读(136) 评论(0) 推荐(0) 编辑