You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1.5 KiB
1.5 KiB
字符串相关
class Solution {
public String replaceSpace(String s) {
StringBuilder builder = new StringBuilder();
int i = 0;
while (i < s.length()) {
char c = s.charAt(i);
if (c == ' ') {
builder.append("%20");
} else {
builder.append(c);
}
i++;
}
return builder.toString();
}
}
class Solution {
public char firstUniqChar(String s) {
if (s.length() == 0) {
return ' ';
}
LinkedHashMap<Character, Integer> map = new LinkedHashMap<>();
for (char c : s.toCharArray()) {
map.put(c, map.getOrDefault(c, 0) + 1);
}
for (Map.Entry<Character, Integer> entry : map.entrySet()) {
if (entry.getValue() == 1) {
return entry.getKey();
}
}
return ' ';
}
}
class Solution {
public char firstUniqChar(String s) {
char[] array = s.toCharArray();
int[] ints = new int[256];
for (char c : array) {
ints[c]++;
}
for (char c : array) {
if (ints[c] == 1) {
return c;
}
}
return ' ';
}
}