今際の国の呵呵君
Sunday, February 22, 2015
[LeetCode]Merge Interval
题目链接
按照start从小到大sort一遍,我们维护一个已经merge了的intervals的集合merged。对于每一个interval,如果其start大于merged尾部interval的end,我们就把interval push到merged中。否则,说明和merged中最后一个interval相交,我们看情况更新merged尾部interval的end。时间复杂度O(n * log n),代码如下:
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment