forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_1844.java
27 lines (25 loc) · 859 Bytes
/
_1844.java
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
package com.fishercoder.solutions;
public class _1844 {
public static class Solution1 {
public String replaceDigits(String s) {
StringBuilder sb = new StringBuilder();
for (char c : s.toCharArray()) {
if (Character.isAlphabetic(c)) {
sb.append(c);
} else {
sb.append((char) (sb.charAt(sb.length() - 1) + Character.getNumericValue(c)));
}
}
return sb.toString();
}
}
public static class Solution2 {
public String replaceDigits(String s) {
char[] inpArr = s.toCharArray();
for (int i = 1; i < inpArr.length; i += 2) {
inpArr[i] = (char) (inpArr[i - 1] + inpArr[i] - '0');
}
return String.valueOf(inpArr);
}
}
}