3174. Clear Digits | leetcode daily challenge | shashcode | java | dsa | shashwat

3174. Clear Digits | leetcode daily challenge | shashcode | java | dsa | shashwat

shashCode

1 месяц назад

1,409 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@shashwat_tiwari_st
@shashwat_tiwari_st - 10.02.2025 06:03

like target is 170. Please do like if you have understood the explanation as well as the code😊😊

Ответить
@PiyushSharma-we8yd
@PiyushSharma-we8yd - 10.02.2025 06:03

done, first❣

Ответить
@pabitradhara3535
@pabitradhara3535 - 10.02.2025 07:11

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

Ответить
@tusharsaxena357
@tusharsaxena357 - 10.02.2025 07:58

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

Ответить
@khushantwankhede8311
@khushantwankhede8311 - 10.02.2025 17:39

waaa waaaa !!!!!!

Ответить
@abhirajxyz7944
@abhirajxyz7944 - 10.02.2025 20:04

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)

Ответить
@abhirajxyz7944
@abhirajxyz7944 - 10.02.2025 20:10

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 .❤

Ответить
@tejas2636
@tejas2636 - 10.02.2025 21:15

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.]

Ответить