-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution50.java
More file actions
33 lines (27 loc) · 755 Bytes
/
Solution50.java
File metadata and controls
33 lines (27 loc) · 755 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package com.usher.algorithm.offer;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* @Author: Usher
* @Description:
*/
public class Solution50 {
public int FirstNotRepeatingChar(String str) {
Map<Character,Integer> map = new LinkedHashMap<>();
for (int i =0;i < str.length();i++){
if (map.containsKey(str.charAt(i))){
int tmp = map.get(str.charAt(i));
map.put(str.charAt(i),tmp+1);
}else {
map.put(str.charAt(i), 1);
}
}
for (int i =0;i < str.length();i++){
char c = str.charAt(i);
if (map.get(c) == 1)
return i;
}
return -1;
}
}