Algorithm/Programmers

[Programmers/C++] 짝지어 제거하기, 효율성1,2,3,4 오류

HAS3ONG 2019. 4. 7. 16:44

출처

https://programmers.co.kr/learn/courses/30/lessons/12973#

 

소스

#include <iostream>
#include <string>
#include <queue>
using namespace std;

int solution(string s)
{
    int answer = 0;
    queue<char> q;
    for(int i = 0; i < s.size(); i++){
        q.push(s[i]);
    }
    queue<char> p;
    int cnt = 1;
    char value;
    char compare;
    while(!q.empty()){
        if(cnt >= q.size()){
            return 0;
        }
        value = q.front();
        q.pop();
        compare = q.front();
        if(value == compare){
            q.pop();
            cnt = 1;
        }
        else{
            q.push(value);
            cnt++;
        }
    }
    answer = 1;

    return answer;
}