웅재의 코딩세상

[프로그래머스] 문자 개수 세기 본문

코딩테스트/프로그래머스 - LV 0

[프로그래머스] 문자 개수 세기

웅드 2024. 1. 31. 13:50

 

 

  • 풀이
#include <string>
#include <vector>

using namespace std;


vector<int> solution(string my_string) {
    vector<int> answer(52,0);
    for(int i=0; i<my_string.size(); i++){
        if(my_string[i] < 'a') answer[my_string[i]- 'A']++;
        else answer[my_string[i] - 'a'+26]++;
    }
    return answer;
}
반응형