Skip to content

Commit cc4b0a5

Browse files
authored
Update 1239-maximum-length-of-a-concatenated-string-with-unique-characters.kt
simplify solution
1 parent a01d94e commit cc4b0a5

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

Diff for: kotlin/1239-maximum-length-of-a-concatenated-string-with-unique-characters.kt

+6-11
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@ class Solution {
33
val charSet = HashSet<Char>()
44

55
fun overlap(s: String): Boolean {
6-
val count = s.freqThisAndSet(charSet)
7-
return count.values.max() > 1
6+
val count = IntArray (26)
7+
8+
for (c in s) count[c - 'a']++
9+
for (c in charSet) count[c - 'a']++
10+
11+
return count.any { it > 1 }
812
}
913

1014
fun backtrack(i: Int): Int {
@@ -25,13 +29,4 @@ class Solution {
2529

2630
return backtrack(0)
2731
}
28-
29-
fun String.freqThisAndSet(set: HashSet<Char>) = buildMap<Char, Int> {
30-
this@freqThisAndSet.forEach { c ->
31-
this[c] = getOrDefault(c, 0) + 1
32-
}
33-
set.forEach { c ->
34-
this[c] = getOrDefault(c, 0) + 1
35-
}
36-
}
3732
}

0 commit comments

Comments
 (0)