题解 | #最大值#

最大值

http://www.nowcoder.com/questionTerminal/c0a95c1c30e94dc190e6acc42cb06930

Python极简无需双指针,滑动窗口即可(因为固定了K):

class Solution:
    def maxValue(self , s , k ):
        l = res = 0
        while l < len(s) and l+k <= len(s):  #判断不超过索引
            if int(s[l:l+k]) > int(res):
                res = s[l:l+k]
            l += 1
        return int(res)
全部评论
其实由于位数一样,可以直接用字典序,最后再转型
点赞 回复 分享
发布于 2022-06-05 17:34

相关推荐

点赞 评论 收藏
分享
给🐭🐭个面试机会...:我擦seed✌🏻
点赞 评论 收藏
分享
评论
3
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务