-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday5.java
More file actions
28 lines (28 loc) · 748 Bytes
/
day5.java
File metadata and controls
28 lines (28 loc) · 748 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
class Solution {
public int firstUniqChar(String s) {
int i=0,j=0,k=0,pp=0;
HashMap<Character,Integer> hm= new HashMap<Character,Integer>();
for(i=0;i<s.length();i++){
if(!hm.containsKey(s.charAt(i))){
hm.put(s.charAt(i),1);
}
else{
j=hm.get(s.charAt(i));
j++;
hm.put(s.charAt(i),j);
}
}
for(i=0;i<s.length();i++){
j=hm.get(s.charAt(i));
if(j==1){
k=s.indexOf(s.charAt(i));
j=k;
pp=1;
break;
}
}
if(pp==0)
j=-1;
return j;
}
}