Skip to content

Commit c59f1a8

Browse files
authored
Create Tony the Cyclist.md
1 parent d2fc3be commit c59f1a8

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
```
2+
class Solution {
3+
public int firstUniqChar(String s) {
4+
//char[] c = s.toCharArray();
5+
Map<Character, Integer> m = new HashMap<>();
6+
for (int i = 0; i < s.length(); i++){
7+
if (m.containsKey(s.charAt(i))){
8+
m.put(s.charAt(i), m.get(s.charAt(i))+1);
9+
}
10+
else {
11+
m.put(s.charAt(i), 1);
12+
}
13+
}
14+
for (int i = 0; i < s.length(); i++){
15+
if (m.get(s.charAt(i)) == 1){
16+
return i;
17+
}
18+
}
19+
return -1;
20+
}
21+
}
22+
```

0 commit comments

Comments
 (0)