Skip to content

Commit bf1e9f0

Browse files
authored
Create 3136. Valid Word (#841)
2 parents 7a73813 + 4b5cf23 commit bf1e9f0

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

3136. Valid Word

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// bitset version
2+
class Solution {
3+
public:
4+
bool isValid(string& word) {
5+
const int n=word.size();
6+
if (n<3) return 0;
7+
bitset<2> v=0;
8+
constexpr unsigned vowels=1|(1<<('e'-'a'))|(1<<('o'-'a'))|(1<<('i'-'a'))|(1<<('u'-'a'));
9+
for(char c: word){
10+
if (!isalpha(c) && !isdigit(c)) return 0;
11+
if (isalpha(c)){
12+
unsigned i=(c>'Z')?c-'a':c-'A';
13+
v[(vowels>>i)&1]=1;
14+
}
15+
}
16+
return v==3;
17+
}
18+
};

0 commit comments

Comments
 (0)