classSolution { public List<Boolean> camelMatch(String[] queries, String pattern) { intn= queries.length; List<Boolean> res = newArrayList<Boolean>(); for (inti=0; i < n; i++) { booleanflag=true; intp=0; for (intj=0; j < queries[i].length(); j++) { charc= queries[i].charAt(j); if (p < pattern.length() && pattern.charAt(p) == c) { p++; } elseif (Character.isUpperCase(c)) { flag = false; break; } } if (p < pattern.length()) { flag = false; } res.add(flag); } return res; } }
[sol1-Python]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
classSolution: defcamelMatch(self, queries: List[str], pattern: str) -> List[bool]: n = len(queries) res = [True] * n for i inrange(n): p = 0 for c in queries[i]: if p < len(pattern) and pattern[p] == c: p += 1 elif c.isupper(): res[i] = False break if p < len(pattern): res[i] = False return res
funccamelMatch(queries []string, pattern string) []bool { n := len(queries) res := make([]bool, n) for i := 0; i < n; i++ { res[i] = true p := 0 for _, c := range queries[i] { if p < len(pattern) && pattern[p] == byte(c) { p++ } elseif unicode.IsUpper(c) { res[i] = false break } } if p < len(pattern) { res[i] = false } } return res }
var camelMatch = function(queries, pattern) { let n = queries.length let res = newArray(n) for (let i = 0; i < n; i++) { res[i] = true let p = 0 for (let j = 0; j < queries[i].length; j++) { let c = queries[i][j] if (p < pattern.length && pattern[p] === c) { p++ } elseif (c.toUpperCase() === c) { res[i] = false break } } if (p < pattern.length) { res[i] = false } } return res };
publicclassSolution { public IList<bool> CamelMatch(string[] queries, string pattern) { int n = queries.Length; IList<bool> res = new List<bool>(); for (int i = 0; i < n; i++) { bool flag = true; int p = 0; foreach (char c in queries[i]) { if (p < pattern.Length && pattern[p] == c) { p++; } elseif (char.IsUpper(c)) { flag = false; break; } } if (p < pattern.Length) { flag = false; } res.Add(flag); } return res; } }