#力扣 LeeCode1784. 检查二进制字符串字段 @FDDLC
发布日期:2021-06-30 21:02:59
浏览次数:2
分类:技术文章
本文共 584 字,大约阅读时间需要 1 分钟。
题目描述:
Java代码:
class Solution { public boolean checkOnesSegment(String s) { for(int i=s.length()-1,cnt,limit=0;i>=0;i--){ for(cnt=0;i>=0&&s.charAt(i)=='1';i--,cnt++); if(cnt>0&&++limit==2)return false; } return true; }}
Java代码二:
class Solution { public boolean checkOnesSegment(String s) { int i=1; for(;i
反着来:
class Solution { public boolean checkOnesSegment(String s) { int i=s.length()-1; for(;i>0&&s.charAt(i)=='0';i--); for(;i>0&&s.charAt(i)=='1';i--); return i==0; }}
转载地址:https://liuxingchang.blog.csdn.net/article/details/114692676 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
路过,博主的博客真漂亮。。
[***.116.15.85]2024年04月06日 01时54分13秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
牛客国庆集训派对Day4——G 区间权值(找规律,双重前缀和)
2019-04-30
牛客国庆集训派对Day5——L 数论之神(找规律/数论)
2019-04-30
CodeForces - 629B Far Relative’s Problem(模拟)
2019-04-30
CodeForces - 1059B Forgery (思维)
2019-04-30
CodeForces - 456C Boredom (dp)
2019-04-30
CodeForces - 960B Minimize the error (思维,贪心)
2019-04-30
CodeForces - 97B Superset (思维/分治/构造)
2019-04-30
CodeForces - 675A Infinite Sequence(简单数论 细节)
2019-04-30
CodeForces - 1042B Vitamins (思维)
2019-04-30
ACM 2013 长沙区域赛 Alice's Print Service (二分 思维)
2019-04-30
ACM 2013 长沙区域赛 Collision (几何)
2019-04-30
CodeForces - 1064A Make a triangle! (简单模拟)
2019-04-30
51Nod - 1183 编辑距离 (dp)
2019-04-30
ACM 2014 鞍山区域赛 E - Hatsune Miku (dp)
2019-04-30
反向传播&梯度下降 的直观理解程序(numpy)
2019-04-30