LeetCode #3223

Minimum Length of String After Operations

1개의 풀이 · C++

문제 원문 보기 ↗

SOLUTION INFO

C++ · main.cpp

main.cpp
class Solution {
public:
    int minimumLength(string s) {
        vector<int> cnt(26);
        for(const char &ch: s)  ++ cnt[ch - 'a'];
        int answer = 0;
        for(int i = 0; i < 26; ++i) {
            if(cnt[i] <= 2) answer += cnt[i];
            else answer += cnt[i] % 2 ? 1 : 2;
        }
        return answer;
    }
};

SOLUTION DESCRIPTION

풀이 설명

등록된 풀이 설명이 없습니다.