mobile wallpaper 1
mobile wallpaper 2
mobile wallpaper 3
mobile wallpaper 4
43 字
1 分钟
LeetCode 407周赛 将1移动至末尾的最大次数
2024-07-22

还是自己菜,在第三道题上直接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)

分享

如果这篇文章对你有帮助,欢迎分享给更多人!

LeetCode 407周赛 将1移动至末尾的最大次数
https://ericonline.cn/posts/leetcode-407周赛-将1移动至末尾的最大次数/
作者
Eric
发布于
2024-07-22
许可协议
CC BY-NC-SA 4.0

部分信息可能已经过时

目录