题解 | #字符个数统计#
字符个数统计
https://www.nowcoder.com/practice/eb94f6a5b2ba49c6ac72d40b5ce95f50
自己使用位图算法原理实现如下,轻量级
public static void countMethod2(String input) {
byte[] btArr = new byte[127];
char[] chars = input.toCharArray();
for (char c : chars) {
if (c > 0 && c < 128) {
btArr[c] = 1;
}
}
int resSum = 0;
for (byte b : btArr) {
resSum += b;
}
System.out.println(resSum);
}
查看11道真题和解析

