Cifs manager 中文显示# PDA - 掌中宝
H*M
1 楼
也是一个google题目
Input several pairs of numbers. The second number in the pair is larger than
the first one. You need to combine the intervals has overlap. eg:
Input: [1 3] [2 4] [5 6]
Output should be [1 4] [5 6]
Another eg: [-3 0] [8 9] [4 6] [1 3] [5 7]
output: [-3 0] [8 9] [1 3] [4 7]
Looking for a O(n) solution.
O(n)的办法没想出来,是o(nlgn)算法
连想加调试的时候花了差不多一小时。小错不断。苦死。
大家想想有没有什么好的O(n)办法吧。
另外我提醒大家,vector你要想erase好几个位置的元素的话,要注意shift..
Input several pairs of numbers. The second number in the pair is larger than
the first one. You need to combine the intervals has overlap. eg:
Input: [1 3] [2 4] [5 6]
Output should be [1 4] [5 6]
Another eg: [-3 0] [8 9] [4 6] [1 3] [5 7]
output: [-3 0] [8 9] [1 3] [4 7]
Looking for a O(n) solution.
O(n)的办法没想出来,是o(nlgn)算法
连想加调试的时候花了差不多一小时。小错不断。苦死。
大家想想有没有什么好的O(n)办法吧。
另外我提醒大家,vector你要想erase好几个位置的元素的话,要注意shift..