All Downloads are FREE. Search and download functionalities are using the official Maven repository.

g1801_1900.s1844_replace_all_digits_with_characters.Solution Maven / Gradle / Ivy

There is a newer version: 1.24
Show 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