Leetcode in Java && Oracle
422 subscribers
8 photos
397 files
400 links
Second channel: @codeforces_java

Let's Develop Together!
Download Telegram
image_2022-02-07_23-24-18.png
48.2 KB
#N1544. Make The String Great
problem link

#solution
class Solution {
public String makeGood(String s) {
Stack<Character> stack = new Stack();
for(char ch: s.toCharArray()){
if(!stack.isEmpty() && Math.abs(stack.peek()-ch) == 32)
stack.pop();
else
stack.push(ch);
}

char temp[] = new char[stack.size()];
int n = stack.size()-1;
while(!stack.isEmpty()){
temp[n--] = stack.pop();
}

return new String(temp);
}
}