博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Leetcode 1180. Count Substrings with Only One Distinct Letter [Python]
阅读量:4089 次
发布时间:2019-05-25

本文共 524 字,大约阅读时间需要 1 分钟。

class Solution:    def countLetters(self, s: str) -> int:        container = []        j = 0        i = 0        while i < len(s):            j = i            while i < len(s)-1 and s[i] == s[i+1]:                i += 1            container.append(s[j:i+1])            i += 1                    def plus(n):            res = 0            while n>=1:                res += n                n -= 1            return res                res = 0        for sustr in container:            res += plus(len(sustr))        return res

 

转载地址:http://hijii.baihongyu.com/

你可能感兴趣的文章
【TINY4412】U-BOOT移植笔记:(12)BEEP驱动
查看>>
单链表的修改和删除
查看>>
C++的三个基本特征:封装、继承、多态
查看>>
C++虚函数的总结
查看>>
什么是URL地址?
查看>>
C++多态的实现方式总结
查看>>
学习C++需要注意的问题
查看>>
C++模板
查看>>
C++双冒号(::)的用法
查看>>
【Unity】封装SQLite管理类
查看>>
【Unity】面试题整理
查看>>
【C#】如何实现一个迭代器
查看>>
【Unity】Destroy和DestroyImmediate的区别
查看>>
【Lua】Mac系统下配置SublimeText的Lua编译环境
查看>>
【C#】利用Conditional属性完成编译忽略
查看>>
【Unity】微信登录后将头像存为bytes,将bytes读取成sprite图片
查看>>
【Unity】使用GPS定位经纬度
查看>>
【UGUI/NGUI】一键换Text/Label字体
查看>>
【C#】身份证本地验证
查看>>
【Unity】坑爹的Bug
查看>>