Комментарии:
like target is 170. Please do like if you have understood the explanation as well as the code😊😊
Ответитьdone, first❣
ОтветитьStringBuilder ans=new StringBuilder();
for(char ch:s.toCharArray()){
if(!Character.isDigit(ch)){
ans.append(ch);
}else{
if(ans.length()!=0){
ans.deleteCharAt(ans.length()-1);
}
}
}
return ans.toString();
100% Faster just use toCharAaray
Bro you are doing an amazing job .
Just one request if that can be accommodated before jumping into the optimized solution can you discuss the brute force approach to that question like how you did yesterday in (count bad pairs question) because in interviews it's expected we start with brute force approach rather than jumping to optimized solutions and the other feedback is just discuss the time complexity and space complexity of the solutions.
apart from that I love your content. Keep it up
waaa waaaa !!!!!!
Ответитьclass Solution:
def clearDigits(self, s: str) -> str:
stack = deque()
for ch in s:
if not stack or ch.isalpha():
stack.append(ch)
elif stack[-1].isalpha():
stack.pop()
else :
stack.append(ch)
return "".join(stack)
In current month I am able to solve all the problems without taking any kind of solution help. But still come to see your and other solutions . thanks for such an amazing work .❤
ОтветитьNiceeeee one, just one thing that is mentioned in the question --> "The input is generated such that it is possible to delete all digits" so we didn't have to worry about stack.isEmpty() or so.length()==0 conditions..🙌🏻
[Testcase will have atleast one character before each digit.]