Recent Posts
«   2025/01   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Today
Total
관리 메뉴

Try

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

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;
}

'Algorithm > Programmers' 카테고리의 다른 글

[Programmers/C++] 올바른 괄호  (0) 2019.04.07
[Programmers/C++] H-Index  (0) 2019.04.07
[Programmers/C++] 예상 대진표  (0) 2019.04.04
[Programmers/Python] 폰켓몬  (0) 2019.04.04
[Programmers/C++] 폰켓몬  (0) 2019.04.04
Comments