Given a string, find the first non-repeating character in it and return it’s index. If it doesn’t exist, return -1.
Examples:
s = "leetcode"
return 0.
s = "loveleetcode",
return 2.
Note: You may assume the string contain only lowercase letters.
用数组,简单粗暴,把字符个数都记录下来,最后遍历一下原来的字符串,判断再这个数组里面的个数就行。
public int firstUniqChar1(String s) {
if (s == null || s.length() == 0)
return -1;
int[]

该博客介绍了一个LeetCode问题,目标是在给定的字符串中找到第一个不重复的字符并返回其索引。如果不存在这样的字符,则返回-1。文章提到了几种解决方案,包括使用数组、Map以及结合List和Map的方法。
订阅专栏 解锁全文
344

被折叠的 条评论
为什么被折叠?



