g0401_0500.s0500_keyboard_row.Solution.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of leetcode-in-kotlin Show documentation
Show all versions of leetcode-in-kotlin Show documentation
Kotlin-based LeetCode algorithm problem solutions, regularly updated
package g0401_0500.s0500_keyboard_row
// #Easy #Array #String #Hash_Table #2023_01_05_Time_170_ms_(85.19%)_Space_35.4_MB_(85.19%)
import java.util.Locale
class Solution {
private fun check(str: String, word: String): Boolean {
for (ch in word.toCharArray()) {
if (str.indexOf(ch) < 0) {
return false
}
}
return true
}
fun findWords(words: Array): Array {
val arr: MutableList = ArrayList()
for (word in words) {
val w = word.lowercase(Locale.getDefault())
if (check("qwertyuiop", w) || check("asdfghjkl", w) || check("zxcvbnm", w)) {
arr.add(word)
}
}
var ans: Array
ans = arr.toTypedArray()
return ans
}
}