Skip to content

Commit 2fdbcab

Browse files
authored
Added Replace All Digits with Characters.java
1 parent 35a2f55 commit 2fdbcab

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution {
2+
public String replaceDigits(String s) {
3+
StringBuilder sb = new StringBuilder();
4+
int n = s.length();
5+
for (int i = 1; i < n; i += 2) {
6+
char c = s.charAt(i - 1);
7+
sb.append(c).append((char) (((int) c) + Character.getNumericValue(s.charAt(i))));
8+
}
9+
return n % 2 != 0 ? sb.append(s.charAt(n - 1)).toString() : sb.toString();
10+
}
11+
}

0 commit comments

Comments
 (0)