LeetCode 407周赛 将1移动至末尾的最大次数


avatar
GuoYulong 2024-07-22 105

还是自己菜,在第三道题上直接g,思路一直不对…………最后code依据灵神思路

class Solution {
public:
    int maxOperations(string s) {
        int result = 0;
        int count = 0;
        for (int i = 0; i < s.length();i++) {
            if (s[i] == '1') {
                count++;
            } else if (i && s[i-1] == '1') {
                result+=count;
            }
        }
        return result;
    }
};

附灵神题解:堵车(Python/Java/C++/Go)

相关阅读

注意!!!

新增会员中心页面,方便管理个人账户,充值功能暂不开启,请勿为本网站进行任何充值活动!!!

通知!!!

① 过年好!!!拖更几个月了已经,年后继续更新!!