We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 2c64d2a commit f509583Copy full SHA for f509583
200318/Solution_programmers_짝지어제거하기_육성현.java
@@ -0,0 +1,29 @@
1
+class Solution {
2
+ int index = 0;
3
+ public int solution(String s) {
4
+ if(s.length()%2==1) return 0;
5
+ char[] stack = new char[s.length()];
6
+ int top = -1;
7
+ stack[++top] = s.charAt(0);
8
+ for(int i =1;i<s.length();i++){
9
+ char prev = stack[top];
10
+ char next = s.charAt(i);
11
+ if(prev==next) {
12
+ if(top==0){
13
+ if(i+1<s.length()){
14
+ stack[top] = s.charAt(i+1);
15
+ i++;
16
+ }else{
17
+ top--;
18
+ }
19
20
21
22
23
+ stack[++top] = next;
24
25
26
+ if(top==-1) return 1;
27
+ else return 0;
28
29
+}
0 commit comments