| https://leetcode.com/problems/summary-ranges | Easy |
|---|
class Solution {
fun summaryRanges(nums: IntArray): List<String> {
val n = nums.size
val res = ArrayList<String>()
if (n == 0) return res
var start = nums[0]
var prev = start
var i = 1
while (i < n) {
val v = nums[i]
if (v.toLong() != prev.toLong() + 1L) {
if (start == prev) res.add(start.toString()) else res.add("$start->$prev")
start = v
}
prev = v
i++
}
if (start == prev) res.add(start.toString()) else res.add("$start->$prev")
return res
}
}