题目:
题解:
构建一份映射关系就好了
public String converterPassword(String oldPassword) {
String a = "ABCDEFGHIJKlMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
String b = "bcdefghijklmnopqrstuvwxyza22233344455566677778889999";
char[] chars = oldPassword.toCharArray();
for (int i = 0; i < chars.length; i++) {
if (chars[i] >= 'A' && chars[i] <= 'Z') {
chars[i] = b.charAt(chars[i] - 'A');
} else if (chars[i] >= 'a' && chars[i] <= 'z') {
chars[i] = b.charAt(chars[i] - 'a' + 26);
}
}
return new String(chars);
}
时间复杂度:O(N)