Skip to content

Commit

Permalink
Update 715.range-module.md
Browse files Browse the repository at this point in the history
  • Loading branch information
azl397985856 authored Jul 5, 2021
1 parent d59fceb commit 6c620a8
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion problems/715.range-module.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class RangeModule(object):

但其实这种做法 overlap 的时间复杂度是 $O(N)$,这部分可以优化。优化点点在于 overlap 的实现,实际上被跟踪的区间是有序的,因此这部分其实也可是二分查找。只不过我写了一半就发现不好根据结束时间查找。

参考了 [这篇题解](https://leetcode.com/problems/range-module/discuss/244194/Python-solution-using-bisect_left-bisect_right-with-explanation "Python solution using bisect_left, bisect_right with explanation") 后发现,其实我们可以将被跟踪的区块一维化处理,这样问题就简单了。比如我们不这样记录被跟踪的区间 [(1,2),(3,6),(8,12)],而是这样:[1,2,3,5,8,12]
参考了 [这篇题解](https://leetcode.com/problems/range-module/discuss/244194/Python-solution-using-bisect_left-bisect_right-with-explanation "Python solution using bisect_left, bisect_right with explanation") 后发现,其实我们可以将被跟踪的区块一维化处理,这样问题就简单了。比如我们不这样记录被跟踪的区间 [(1,2),(3,5),(8,12)],而是这样:[1,2,3,5,8,12]

经过这样的处理, 数组的奇数坐标就是区间的结束点,偶数坐标就是开始点啦。这样二分就不需要像上面一样使用元组,而是使用单值了。

Expand Down

0 comments on commit 6c620a8

Please sign in to comment.