Skip to content

Commit 103ee64

Browse files
refactor 387
1 parent 24e24b2 commit 103ee64

File tree

1 file changed

+12
-23
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+12
-23
lines changed
Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,18 @@
11
package com.fishercoder.solutions;
22

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-
143
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;
2416
}
25-
}
26-
return -1;
2717
}
28-
}
2918
}

0 commit comments

Comments
 (0)