Leetcode / 3174. Clear Digits
Pick a programming language:
Here is the source code for the solution to this problem.
class Solution {
public String clearDigits(String s) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < s.length(); i++) {
if (Character.isDigit(s.charAt(i))) {
if (sb.length() > 0) {
sb.deleteCharAt(sb.length() - 1);
}
}
else {
sb.append(s.charAt(i));
}
}
return sb.toString();
}
}
Did you like the lesson? 😆👍
Consider a donation to support our work: