题解 | #合并区间#

合并区间

http://www.nowcoder.com/practice/69f4e5b7ad284a478777cb2a17fb5e6a

题解: 使用sort函数 进行数组start 和 end进行判断 bool cmp(a , b){ if a.start == b .start return a.end < b .end return a.start < b .start }

sort(, , cmp); 遍历数组 if (重合) 合并 num[i].start 与end进行复制
else 将num[i-1] 放到数组中;

最后将最后一个元素放到数组中 返回

全部评论

相关推荐

被普调的六边形战士很高大:项目经历貌似和专业或者求职方向没大关系?
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务