Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

format #141

Merged
merged 1 commit into from
Jun 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions count-vowel-strings-in-ranges/index.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,23 @@ package com.github.masx200.leetcode_test.count_vowel_strings_in_ranges

class Solution {
fun vowelStrings(words: Array<String>, queries: Array<IntArray>): IntArray {


val prefixs = IntArray(words.size) { 0 }

words.forEachIndexed { i, s ->
if (i == 0) {

prefixs[i] = booleanToInt(isVowelString(s))
} else {
prefixs[i] = prefixs[i - 1] + booleanToInt(isVowelString(s))

}

}
return IntArray(queries.size) {
val li = queries[it][0]
val ri = queries[it][1]
if (li == ri) booleanToInt(isVowelString(words[li])) else prefixs[ri] - if (li == 0) 0 else prefixs[li - 1]
}
}
private val vowels = hashSetOf('a', 'e', 'i', 'o', 'u')
private val vowels = hashSetOf('a', 'e', 'i', 'o', 'u')
private fun isVowelString(s: String): Boolean {

return s.isNotEmpty() && vowels.contains(s[0]) && vowels.contains(s.last())
}

Expand Down