Skip to content

Commit b90e783

Browse files
authored
Create 0387-first-unique-character-in-a-string.kt
1 parent aa7f4e1 commit b90e783

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Diff for: kotlin/0387-first-unique-character-in-a-string.kt

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution {
2+
fun firstUniqChar(s: String): Int {
3+
var count = IntArray (26)
4+
for (c in s)
5+
count[c - 'a']++
6+
7+
for ((i, c) in s.withIndex()) {
8+
if (count[c - 'a'] == 1)
9+
return i
10+
}
11+
12+
return -1
13+
}
14+
}

0 commit comments

Comments
 (0)