###### leetcode: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”
return 0.

s = “loveleetcode”,
return 2.

public class Solution {
public int firstUniqChar(String s) {
int[] vis = new int[26];
Arrays.fill(vis, Integer.MAX_VALUE - 1);
for(int i = 0; i < s.length(); ++i){
int index = s.charAt(i) - 'a';
if(vis[index] == Integer.MAX_VALUE)continue;
else if(vis[index] == Integer.MAX_VALUE - 1){
vis[index] = i;
}else{
vis[index] = Integer.MAX_VALUE;
}
}
int min = Integer.MAX_VALUE - 2;
for(int i : vis){
if(i < min)min = i;
}
return min == Integer.MAX_VALUE - 2 ? -1 : min;
}

}

#### 【LeetCode】387 First Unique Character in a String（java实现）

2016-10-20 00:37:41

#### 【python】【leetcode】【算法题目387—First Unique Character in a String】

2016-12-04 14:18:57

#### 387.leetcode First Unique Character in a String(easy)[统计字符串字符次数]

2016-08-22 19:51:53

#### First Unique Character in a String（字符串中的第一个唯一字符）

2016-09-22 11:18:17

#### 387. First Unique Character in a String

2016-08-22 22:18:16

#### 387. First Unique Character in a String Java

2016-09-04 18:37:49

#### leetcode 387 First Unique Character in a String C++

2016-08-25 20:42:31

#### LeetCode387—First Unique Character in a String

2016-08-26 21:46:52

#### first unique character in a string

2014-09-21 08:26:44

#### LeetCode--First Unique Character in a String（字符串中第一个不重复的字母）Python

2017-12-04 15:01:54

## 不良信息举报

leetcode:First Unique Character in a String