We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents ac4d8ed + 76e0c19 commit 130333eCopy full SHA for 130333e
2018.12.1-leetcode387/。。。.md
@@ -0,0 +1,19 @@
1
+class Solution {
2
+ public int firstUniqChar(String s) {
3
+ if (s.trim().length() == 0)return -1;
4
+ int result = Integer.MAX_VALUE;
5
+ Map<Character,Integer> map = new HashMap<>();
6
+ for (int i = 0; i < s.length(); i++){
7
+ if (map.containsKey(s.charAt(i))){
8
+ map.put(s.charAt(i),Integer.MAX_VALUE);
9
+ }else {
10
+ map.put(s.charAt(i),i);
11
+ }
12
13
+ for (int i : map.values()){
14
+ result = Math.min(i,result);
15
16
+ if (result == Integer.MAX_VALUE)result=-1;
17
+ return result;
18
19
+}
0 commit comments