1 Star 1 Fork 1

Clock966 / LeetcodeEveryday

forked from 四方云和 / LeetcodeEveryday 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
FirstUniqueCharacterInAString.java 415 Bytes
一键复制 编辑 原始数据 按行查看 历史
RunAtWorld 提交于 2020-03-31 00:18 . Java 语言解答 package
package solution;
public class FirstUniqueCharacterInAString {
// 耗时21ms,O(2n)
public int firstUniqChar(String s) {
int[] cnt = new int[26];
for (char c : s.toCharArray()) {
cnt[c - 'a']++;
}
for (int i = 0; i < s.length(); i++) {
if (cnt[s.charAt(i) - 'a'] == 1) {
return i;
}
}
return -1;
}
}
1
https://gitee.com/Clock966/LeetcodeEveryday.git
git@gitee.com:Clock966/LeetcodeEveryday.git
Clock966
LeetcodeEveryday
LeetcodeEveryday
master

搜索帮助