Description
Given a sorted integer array without duplicates, return the summary of its ranges.
For example, given [0,1,2,4,5,7], return [“0->2”,”4->5”,”7”].
Credits:
Special thanks to @jianchao.li.fighter for adding this problem and creating all test cases.
Solution
|
|
Analyse
这里思路很简单,每一次count更新都是为了下一次的操作。在结束的时候,再统计一下结尾的值。复杂度O(n),我觉得已经是很好的的解法了。
Optimization
|
|
Analyse
这个只是代码更短,但是明显复杂度更高,需要O(n ^ 2)复杂度,所以不推荐,还是我的方法好。