LeetCode Summary Ranges

BabbleDay posted @ 2015年7月17日 05:00 in 刷题防身 with tags LeetCode Summary Ranges Python , 651 阅读

心得:特殊情况还是单独处理,可以简化思路,代码正确实现后,再考虑合并特殊情况

 

def summaryRanges(self, nums):
        rtn = []
        if len(nums) == 0:
            return rtn
        if len(nums) == 1:
            rtn.append(str(nums[0]))
            return rtn

        i = 0
        while(i<len(nums)):
            start = nums[i]
            end = nums[i]
            while(i+1<len(nums) and end+1 == nums[i+1]):
                end = nums[i+1]
                i += 1

            if start==end:
                rtn.append(str(start))
            else:
                rtn.append(str(start)+"->"+str(end))
            i += 1
        
        return rtn
Avatar_small
celebrity heights 说:
2023年6月10日 16:44

This is very helpful for me, and the people who are looking for info about celeb height wiki

Avatar_small
bravotv.com/link act 说:
2023年7月10日 04:35

The activation code will appear on the TV screen when the streaming device has been connected. To enter the activation code, go to the official website. First, you must log in to your TV provider and then select the Activate Now option to begin the activation procedure. bravotv.com/link activation code roku Users may log in to the Bravo TV channel on their Smart TV or streaming device with this code and the service is now available on Android, Roku, Amazon Fire TV, Apple TV, iOS devices, computers, tablets, and Smart TVs.

Avatar_small
CBSE 2nd Class Spli 说:
2023年8月20日 23:44

CBSE Curriculum is based on the National Curriculum Framework and Provides Opportunities for Students to Achieve Excellence in Learning, CBSE Provides the Syllabus for 2nd Class, This new Syllabus CBSE 2nd Class Split up Syllabus 2024 are Designed Strategically by a Team of Subject Experts and are Prescribed by the Ministry of Human Resource Development, formerly Ministry of Education, is Responsible for the Development of Human Resources in India, Primary Level Syllabus for the Children of has been developed with the Supervision of the Central Board of Secondary Education.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter