Mengbing Wang
Mengbing Wang
Python 版本的,自定义带删除功能的堆。直接在heapq上包了一层,更好的办法是参考labuladong堆的实现文章里的方法。 startMap 和 endMap定义稍有不同,搞的有点复杂。 ```py class MyHeap: def __init__(self): self.data = [] self.deleted = set() def top(self): self.lazy_deletion() return self.data[0] def pop(self): self.lazy_deletion() return heapq.heappop(self.data) def delete(self, key): self.deleted.add(key)...
想到一个类似的题,力扣679题 24点游戏,还是非常经典的dfs。
发现弹栈的时机有两种,本文和力扣官方解答分别用到了这两种。 调用者弹栈 ``` class Solution: def dfs(self, node, graph, path, endnote): path += [node] if path and path[-1] == endnote: self.ans.append(path[:]) return for nodeNext in graph[node]: self.dfs(nodeNext, graph, path, endnote)...
官方题解的贪心没有排序,是O(time+n)的复杂度。没有这里的答案好理解。
Hi, The PR is created: [23522](https://github.com/openvinotoolkit/openvino/pull/23522)