-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_3136.java
29 lines (27 loc) · 960 Bytes
/
_3136.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package com.fishercoder.solutions.fourththousand;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
public class _3136 {
public static class Solution1 {
public boolean isValid(String word) {
if (word.length() < 3) {
return false;
}
Set<Character> vowels =
new HashSet<>(Arrays.asList('a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'));
boolean containsVowel = false;
boolean containsConsonant = false;
for (char c : word.toCharArray()) {
if (vowels.contains(c)) {
containsVowel = true;
} else if (Character.isAlphabetic(c)) {
containsConsonant = true;
} else if (!Character.isDigit(c)) {
return false;
}
}
return containsVowel && containsConsonant;
}
}
}