【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;

做自己该做的事情,做自己喜欢做的事情,安静做一枚有思想的技术媛。
版权声明,转载请注明出处:https://www.cnblogs.com/happyamyhope/
原文地址:https://www.cnblogs.com/happyamyhope/p/13964546.html