387. First Unique Character in a String
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" |
Note:
You may assume the string contain only lowercase letters.
自己的解法
开始觉的遍历 char[] 然后判断在 String 的首位置和末位置,若一样就返回索引。呃,感觉有点偷鸡
public int firstUniqChar(String s) { |
查了下别人的,又是 new int[26]
public int firstUniqChar(String s) { |
但是在运行时间上,下面的方法更快