g1801_1900.s1844_replace_all_digits_with_characters.Solution Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of leetcode-in-java Show documentation
Show all versions of leetcode-in-java Show documentation
Java-based LeetCode algorithm problem solutions, regularly updated
The newest version!
package g1801_1900.s1844_replace_all_digits_with_characters;
// #Easy #String #2022_05_07_Time_1_ms_(70.12%)_Space_42.3_MB_(43.95%)
public class Solution {
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();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy