LIUPENG BLOG
Liupeng
Jun 7, 2020
It takes 1 minutes to read this article.

分割字符串的最大得分


Title

截屏2020-06-07 下午5.39.13

MyCode

int Paly1422::maxScore(std::string s) {
    auto max = 0, temp = 1;
    auto length = s.length();
    if (length == 0) return 0;
    for (int i = 1; i < length; i++) {
        max = max + temp * (s[i] - '0');
    }
    std::cout << max << std::endl;
    auto a = 0, b = max;
    if (s[0] == '0') a = a + 1;
    for (int i = 1; i < length; i++) {
        max = (a + b >= max) ? (a + b) : max;
        if (s[i] == '0') a = a + 1;
        if (s[i] == '1') b = b - 1;
        std::cout << max << std::endl;
    }
    return max;
}

Result

截屏2020-06-07 下午5.40.42