1047. Remove All Adjacent Duplicates In String || In JAVA || Easy Way #leetcode

preview_player
Показать описание
Hello Friends,
here I have discussed a leetcode problem. I solved this in JAVA.
I hope this video will help you.:)
Feel free to ask if you have any questions and you can give me any suggestions that I can improve!

Thanks for watching!

Leetcode Problems:
Рекомендации по теме
Комментарии
Автор

Code:-

class Solution {
public String removeDuplicates(String s) {

Stack<Character> sk = new Stack<>();

for(char c : s.toCharArray()){
if(sk.size()>=1){

if(sk.peek() == c)
sk.pop();
else
sk.push(c);

}
else{
sk.push(c);
}
}

String str = "";

for(char c : sk){
str=str+c;
}

return str;
}
}

quicklearninigwithsree
visit shbcf.ru