摘要: 参考:https://leetcode.com/problems/sum-of-mutated-array-closest-to-target/discuss/464211/Python-Binary-Search 补充另一个,使用Java实现的代码,可读性好一些: 参考:https://leetc 阅读全文
posted @ 2019-12-29 17:15 Sempron2800+ 阅读(227) 评论(0) 推荐(0)
摘要: 算法思想:二叉树层次遍历。 阅读全文
posted @ 2019-12-29 14:09 Sempron2800+ 阅读(182) 评论(0) 推荐(0)
摘要: 从右向左遍历,每次更新右区间的最大值maxright,并将这个值插入结果数组的0下标位置。 阅读全文
posted @ 2019-12-29 13:56 Sempron2800+ 阅读(152) 评论(0) 推荐(0)
摘要: 算法思路:BFS。 先记录所有的0值元素的下标,作为初始集合。使用两层遍历,找出每到每个可达点存入下一层的集合。 使用visited进行缓存,过滤重复访问过的点,防止出现环,而死循环。 阅读全文
posted @ 2019-12-29 11:20 Sempron2800+ 阅读(170) 评论(0) 推荐(0)
摘要: 分别使用中序遍历两颗二叉搜索树,得到两个有序列表。再将两个数组合并为一个有序数组。 阅读全文
posted @ 2019-12-29 11:17 Sempron2800+ 阅读(169) 评论(0) 推荐(0)
摘要: 1 class Solution: 2 def sumZero(self, n: int) -> List[int]: 3 res = [] 4 k = n // 2 5 i = 1 6 for j in range(k): 7 res.append(i) 8 res.append(i * (-1)) 9 i += 1 10 if n % 2 == 1: 11 res.append(0) 12 r 阅读全文
posted @ 2019-12-29 11:16 Sempron2800+ 阅读(134) 评论(0) 推荐(0)