-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClearDigits.java
More file actions
36 lines (31 loc) · 904 Bytes
/
ClearDigits.java
File metadata and controls
36 lines (31 loc) · 904 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import java.util.*;
public class ClearDigits {
private static String remove(String s) {
StringBuilder sb = new StringBuilder(s);
int i = 0;
while (i < sb.length()) {
char ch = sb.charAt(i);
if (Character.isDigit(ch)) {
int left = i - 1;
while (left >= 0 && Character.isDigit(sb.charAt(left))) {
left--;
}
if (left >= 0) {
sb.deleteCharAt(left);
i--;
}
sb.deleteCharAt(i);
} else {
i++;
}
}
return sb.toString();
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String s = sc.nextLine();
String ans = remove(s);
System.out.println(ans);
sc.close();
}
}