class Solution { public: int maxN(string &;s) { int res = 0; stack<int> stk; stk.push(0); for (int i = 1; i < s.length(); ++i) { if (s[stk.top()] == '1' &;&; s[i] == '0') stk.pop(); else stk.push(i); } stk.push(s.length()); int pre = stk.top(); stk.pop(); while (!stk.empty()) { res = max(res, pre - stk.top() - 1); stk.pop(); } return res; } };
点赞 评论

相关推荐

不愿透露姓名的神秘牛友
11-10 11:42
点赞 评论 收藏
分享
10-31 20:07
门头沟学院 Java
点赞 评论 收藏
分享
12-19 22:04
武汉大学 Java
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务