Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcc4b0a5

Browse files
authored
Update 1239-maximum-length-of-a-concatenated-string-with-unique-characters.kt
simplify solution
1 parenta01d94e commitcc4b0a5

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

‎kotlin/1239-maximum-length-of-a-concatenated-string-with-unique-characters.kt

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

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

1014
funbacktrack(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)

[8]ページ先頭

©2009-2025 Movatter.jp