题解 | 小红的双生串

小红的双生串

https://www.nowcoder.com/practice/099d6681234d4e3e95c0e0ade31929da

#include <bits/stdc++.h>
using namespace std;

unordered_map<char,int> mp1,mp2;
int ma1 = -1,ma2 = -1;

int main() {
    string str;
    cin>>str;
    int len = str.size()>>1;

    for(int i = 0;i<len;i++){
        ma1 = max(ma1,++mp1[str[i]]);
    }
    for(int i = len;i<str.size();i++){
        ma2 = max(ma2,++mp2[str[i]]);
    }

    cout<<2*len-ma1-ma2;

    return 0;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

喜欢核冬天的哈基米很想上市:会爆NullPointerException的
点赞 评论 收藏
分享
大佬们,在大厂实习的都是几百一天???
爱睡觉的冰箱哥:实习工资这个不都是公开的吗,a不了,字节400,快手350,有些有房补餐补这样
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务