-
Notifications
You must be signed in to change notification settings - Fork 352
Expand file tree
/
Copy pathch-1.kt
More file actions
37 lines (36 loc) · 742 Bytes
/
Copy pathch-1.kt
File metadata and controls
37 lines (36 loc) · 742 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
fun firstunique(s: String): Int {
var cc = mutableMapOf<Char,Int>()
for (c in s.toCharArray()) {
if (cc.containsKey(c)) {
cc[c] = cc[c]!! + 1
} else {
cc[c] = 1
}
}
for ((i,c) in s.toCharArray().withIndex()) {
if (cc[c] == 1) {
return i
}
}
return -1
}
fun main() {
if (firstunique("Perl Weekly Challenge") == 0) {
print("Pass")
} else {
print("FAIL")
}
print(" ")
if (firstunique("Long Live Perl") == 1) {
print("Pass")
} else {
print("FAIL")
}
print(" ")
if (firstunique("aabbcc") == -1) {
print("Pass")
} else {
print("FAIL")
}
println("")
}