Skip to content

Commit fdbaa1a

Browse files
authored
Create 387. First Unique Character in a String.java
1 parent 17edbce commit fdbaa1a

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Diff for: 387. First Unique Character in a String.java

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// https://leetcode.com/problems/first-unique-character-in-a-string
2+
3+
public class Solution {
4+
public int firstUniqChar(String s) {
5+
int[] freq = new int[26];
6+
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+
return -1;
15+
}
16+
}

0 commit comments

Comments
 (0)