Leetcode-228题:Summary Ranges

题目

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"].

思路

用两个指针来确定一个区间

代码

class Solution(object):
    def summaryRanges(self, nums):
        """
        :type nums: List[int]
        :rtype: List[str]
        """
        res = []
        l = 0
        while l < len(nums):
            r = l
            while r+1'+str(nums[r]))
                l = r+1
        return res

你可能感兴趣的:(Leetcode-228题:Summary Ranges)