-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprblm1544.java
More file actions
29 lines (25 loc) · 781 Bytes
/
prblm1544.java
File metadata and controls
29 lines (25 loc) · 781 Bytes
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
import java.util.*;
public class prblm1544 {
public static void main(String[] args) {
String s = "leEeetcode";
System.out.println(makeGood(s));
}
public static String makeGood(String s) {
Stack<Character> result = new Stack<>();
for (int i = 0; i < s.length(); i++) {
char curr = s.charAt(i);
if(!result.isEmpty() && Math.abs(result.peek() - curr) == 32){
result.pop();
}
else{
result.push(curr);
}
}
StringBuilder str = new StringBuilder();
int size = result.size();
for (int i = 0; i < size; i++) {
str.append(result.pop());
}
return str.reverse().toString();
}
}