-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution3136.go
More file actions
50 lines (44 loc) · 1.06 KB
/
solution3136.go
File metadata and controls
50 lines (44 loc) · 1.06 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package solution3136
// ============================================================================
// 3136. Valid Word
// URL: https://leetcode.com/problems/valid-word/
// ============================================================================
/*
goos: linux
goarch: amd64
pkg: GoLeetCode/solutions/3136---Valid-Word
cpu: 13th Gen Intel(R) Core(TM) i7-13700K
BenchmarkIsValid
BenchmarkIsValid-24 133429677 10.96 ns/op 0 B/op 0 allocs/op
PASS
*/
func isValid(word string) bool {
if len(word) < 3 {
return false
}
// abcdefghijklmnopqrstuvwxyz
letters := "10001000100000100000100000"
hasVowel := false
hasConsonant := false
for _, ch := range word {
switch {
case ch >= 'a' && ch <= 'z':
if letters[ch-'a'] == '1' {
hasVowel = true
} else {
hasConsonant = true
}
case ch >= 'A' && ch <= 'Z':
if letters[ch-'A'] == '1' {
hasVowel = true
} else {
hasConsonant = true
}
case ch >= '0' && ch <= '9':
continue
default:
return false
}
}
return hasVowel && hasConsonant
}