웅재의 코딩세상

[프로그래머스] x 사이의 개수 본문

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

[프로그래머스] x 사이의 개수

웅드 2024. 1. 31. 15:59

 

 

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

using namespace std;

vector<int> solution(string myString) {
    vector<int> answer;
    string s="";
    for(int i=0; i<myString.size(); i++){
        if(myString[i] == 'x') {
            answer.push_back(s.size());
            s = "";
        }
        else s += myString[i];
    }
    answer.push_back(s.size());
    return answer;
}
반응형