Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // может быть нужно отсортировать
- func summaryRanges(_ nums: [Int]) -> [String] {
- if nums.isEmpty {
- return []
- }
- var r = 0
- var l = 0
- var result = [String]()
- for i in 1..<nums.count {
- if nums[i] != nums[r] + 1 {
- if r == l {
- result.append("\(nums[l])")
- } else {
- result.append("\(nums[l])->\(nums[r])")
- }
- l = i
- }
- r += 1
- }
- if r == l {
- result.append("\(nums[l])")
- } else {
- result.append("\(nums[l])->\(nums[r])")
- }
- return result
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement