上一页 1 ··· 35 36 37 38 39 40 41 42 43 ··· 114 下一页
摘要: 算法思路:贪心。 先将数组排序,然后按照顺序添加到顺序字典中。 另记录一个key值从小到大的列表。 每次从key列表中选择最小的元素,作为组头,当前组的剩余k-1个元素,依次+1。如果不满足这个条件,则返回False。 如果全部的元素都能分配到对应的组中,就表示符合题意。 阅读全文
posted @ 2019-12-22 13:26 Sempron2800+ 阅读(153) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution: 2 def findNumbers(self, nums: List[int]) -> int: 3 n = len(nums) 4 count = 0 5 for i in range(n): 6 s = str(nums[i]) 7 if len(s) ... 阅读全文
posted @ 2019-12-22 13:21 Sempron2800+ 阅读(203) 评论(0) 推荐(0) 编辑
摘要: 按照从小到大的顺序生成递增序列,每生成一个序列,判断是否在限定区间内。 如果超过了区间的上限,则跳过本轮循环(因为后面的值会更大)。 阅读全文
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) 编辑
上一页 1 ··· 35 36 37 38 39 40 41 42 43 ··· 114 下一页