File tree Expand file tree Collapse file tree 1 file changed +12
-23
lines changed
src/main/java/com/fishercoder/solutions Expand file tree Collapse file tree 1 file changed +12
-23
lines changed Original file line number Diff line number Diff line change 1
1
package com .fishercoder .solutions ;
2
2
3
- /**
4
- * 387. First Unique Character in a String Given a string, find the first non-repeating character in
5
- * it and return it's index. If it doesn't exist, return -1.
6
- *
7
- * Examples:
8
- *
9
- * s = "leetcode" return 0.
10
- *
11
- * s = "loveleetcode", return 2. Note: You may assume the string contain only lowercase letters.
12
- */
13
-
14
3
public class _387 {
15
- public static class Solution1 {
16
- public static int firstUniqChar (String s ) {
17
- int [] freq = new int [26 ];
18
- for (int i = 0 ; i < s .length (); i ++) {
19
- freq [s .charAt (i ) - 'a' ]++;
20
- }
21
- for (int i = 0 ; i < s .length (); i ++) {
22
- if (freq [s .charAt (i ) - 'a' ] == 1 ) {
23
- return i ;
4
+ public static class Solution1 {
5
+ public static int firstUniqChar (String s ) {
6
+ int [] freq = new int [26 ];
7
+ for (int i = 0 ; i < s .length (); i ++) {
8
+ freq [s .charAt (i ) - 'a' ]++;
9
+ }
10
+ for (int i = 0 ; i < s .length (); i ++) {
11
+ if (freq [s .charAt (i ) - 'a' ] == 1 ) {
12
+ return i ;
13
+ }
14
+ }
15
+ return -1 ;
24
16
}
25
- }
26
- return -1 ;
27
17
}
28
- }
29
18
}
You can’t perform that action at this time.
0 commit comments