본문 바로가기

Programmers/효율성 시간초과 모음

[프로그래머스] 짝지어 제거하기

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include<string>
#include <vector>
using namespace std;
//효율성 테스트 시간초과
int solution(string s)
{
    int answer = 0;
    int i = 0;
   while(i < s.length()) {
        if (s[i] == s[i+1]) {
            s.erase(i, 2); i = 0;
        }
       else i++;
      
       if (s.length() == 0) answer = 1;
    }
 
    return answer;
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter