【leetcode_easy_string】1422. Maximum Score After Splitting a String

problem

1422. Maximum Score After Splitting a String

solution#1: 

code

class Solution {
public:
    int maxScore(string s)
    {
        int left = 0, right = 0;
        for(auto c:s)
        {
            if(c=='1') right++;
        }
        int res = 0;
        for(int i=0; i<s.size()-1; i++)  // substr size more than one.
        {
            if(s[i]=='0') left++;
            else right--;
            res = max(res, left+right);
        }
        return res;
    }
};

可以通过其中一个的计数,改变另一个的计数;

参考

1. leetcode_easy_string_1422. Maximum Score After Splitting a String;

posted on 2021-04-26 20:48  鹅要长大  阅读(18)  评论(0编辑  收藏  举报

导航