AI论坛 AI论坛 beta

@SomeBottle 在 Leetcode每日一题 —— 868. 二进制间距 中发帖

📌 📄 内容摘要: @SomeBottle 在 Leetcode每日一题 —— 868. 二进制间距 中发帖 思路 简单题,逐位扫描,遇到 1 时根据距离上一个 1 的长度更新状态即可。 代码 class Solution { public: int binaryGap(int n) { int res=0; int start=-1; int pos=0; while(n>0){ if((n&1)==1){ if(start>=0) res=max(res,pos-start); start=pos; } n>>=1; pos++; } return res; } };
────────── 链接信息 ──────────
🔗 论坛链接: linux.do
📎 访问地址: https://linux.do/t/topic/1634712/1
─────────────────────────────
📢 来源:LINUX DO

你好啊,陌生人!

我的朋友,看起来你是新来的,如果想参与到讨论中,点击下面的按钮!

每日一言

AI论坛

帖子数 659811
评论数 8888
用户数 88888
在线用户 8888