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.
这里写都是小写字母,如果还有其他奇怪的字符,那么我就选择使用Map来处理,和使用数组也是类似的
ublic static int firstUniqChar(String s) { int[] arr = new int[26]; for(int i =0;i
public static void main(String[] args) { System.out.println(firstUniqChar("leetcode")); System.out.println(firstUniqChar("loveleetcode"));}
输出:
git:https://github.com/woshiyexinjie/leetcode-xin