又到codewar每日刷题时刻,今天抽到的题依旧是难度5
题目:
In the following 6 digit number:
283910
91 is the greatest sequence of 2 digits.
Complete the solution so that it returns the largest five digit number found within the number given.. The number will be passed in as a string of only digits. It should return a five digit integer. The number passed may be as large as 1000 digits.
Adapted from ProjectEuler.net
中文简介:
从输入的若干连续数字(输入为字符串)中提取其中连续的最大5位数(整数输出)
想法:
1.最大连续5位数,首先想到的是历遍每个数位,然后截取连续的5位进行,不过这样数字位太多的时候过于繁杂
2.数字大小可以根据首位数的大小进行筛选,这样可以减少一大部分运算,可以通过集合来判断首位最大数
3.从原字符串中截取首位为最大数的5位连续数字,建立列表,然后进行排序
实现:
def solution(digits):
big = sorted(