"""
main idea: keep check if start and end point is the same. if not using format with ->, else push start point only, restart a new start for the next loop.

tricky point: need to consider when iterate to end, check if start == end 

"""
class Solution:
    def summaryRanges(self, nums: List[int]) -> List[str]:
    # time O(N) space O(1)
        if not nums:
            return []
        start = 0
        end  = None
        size = len(nums)
        res = []
        for cur in range(size):
            if cur + 1 < size and nums[cur+1]- nums[cur] != 1:
                # push start- end 
                end = cur
                if start == end:
                    res.append(str(nums[start]))
                else:
                    res.append(f'{nums[start]}->{nums[end]}')
                start = cur+1
                end = None
        if start == size-1:
            res.append(str(nums[start]))
        else:
            end = size -1
            res.append(f'{nums[start]}->{nums[end]}')
        return res