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

Commit795ab56

Browse files
committed
Time: 106 ms (63.64%), Space: 46 MB (18.18%) - LeetHub
1 parent6528be8 commit795ab56

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* // This is the Master's API interface.
3+
* // You should not implement it, or speculate about its implementation
4+
* interface Master {
5+
* fun guess(word: String): Int {}
6+
* }
7+
*/
8+
classSolution {
9+
privatefun String.partialMatches(other:String):Int {
10+
return foldIndexed(0) { j, acc, char-> acc+ (if (char== other[j])1else0) }
11+
}
12+
13+
funfindSecretWord(words:Array<String>,master:Master) {
14+
words.sortBy { it.toCharArray().distinct().size }
15+
16+
val isRemoved= mutableSetOf<String>()
17+
18+
for (wordin words) {
19+
if (wordin isRemoved) {
20+
continue
21+
}
22+
23+
val guessed= master.guess(word)
24+
if (guessed==6) {
25+
return
26+
}
27+
28+
isRemoved+= words.filter {
29+
it!in isRemoved&& it.partialMatches(word)!= guessed
30+
}
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp