Skip to content

Commit 0316fb6

Browse files
add 3136
1 parent c2326d1 commit 0316fb6

File tree

1 file changed

+36
-3
lines changed

1 file changed

+36
-3
lines changed

contest/src/main/java/com/github/contest/strings/StringsLeetcode.kt

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.github.contest.strings
22

3-
import java.math.BigInteger
4-
53
/**
64
* 848. Shifting Letters
75
*/
@@ -389,7 +387,6 @@ fun lengthOfLastWord(s: String): Int {
389387
}
390388

391389

392-
393390
/**
394391
* 2138. Divide a String Into Groups of Size k
395392
*/
@@ -438,4 +435,40 @@ private fun remainingFill(strs: Array<String>, pattern: Char, k: Int) {
438435
}
439436
}
440437

438+
/**
439+
* 3136. Valid Word
440+
*/
441+
442+
fun isValid(word: String): Boolean {
443+
if (word.length < 3) return false
444+
445+
var vowels = 0
446+
var consonants = 0
447+
448+
for (char in word) {
449+
if (isNotDigit(char) && isNotLetter(char)) return false
450+
if (isLetter(char)) {
451+
if (isVowel(char)) vowels++
452+
else consonants++
453+
}
454+
}
455+
456+
return !(vowels == 0 || consonants == 0)
457+
}
458+
459+
private fun isNotDigit(char: Char) = when {
460+
char in '0'..'9' -> false
461+
else -> true
462+
}
463+
464+
private fun isNotLetter(char: Char) = when {
465+
char in 'a'..'z' || char in 'A'..'Z' -> false
466+
else -> true
467+
}
468+
469+
private fun isVowel(char: Char) = when {
470+
char in "aeiou" || char in "AEIOU" -> true
471+
else -> false
472+
}
473+
441474

0 commit comments

Comments
 (0)