-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy path1023.Camelcase-Matching.go
More file actions
57 lines (47 loc) · 972 Bytes
/
1023.Camelcase-Matching.go
File metadata and controls
57 lines (47 loc) · 972 Bytes
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
51
52
53
54
55
56
57
// https://leetcode.com/problems/camelcase-matching/
//
// algorithms
// Medium (58.14%)
// Total Accepted: 3,358
// Total Submissions: 5,776
// beats 100.0% of golang submissions
package leetcode
func camelMatch(queries []string, pattern string) []bool {
queryLen := len(queries)
res := make([]bool, queryLen)
for i := 0; i < queryLen; i++ {
res[i] = isMatch(queries[i], pattern)
}
return res
}
func isMatch(word, pattern string) bool {
wLen, pLen := len(word), len(pattern)
if wLen < pLen {
return false
}
wIdx, pIdx := 0, 0
for pIdx < pLen && wIdx < wLen {
pIsUpper := isUpperCase(pattern[pIdx])
for wIdx < wLen && word[wIdx] != pattern[pIdx] {
if pIsUpper && isUpperCase(word[wIdx]) {
return false
}
wIdx++
}
pIdx++
wIdx++
}
for wIdx < wLen && !isUpperCase(word[wIdx]) {
wIdx++
}
if wIdx == wLen {
return true
}
return false
}
func isUpperCase(ch byte) bool {
if ch <= 90 {
return true
}
return false
}