LeetCode 1023. Camelcase Matching

Problem Statement


impl Solution {
fn try_match(q: &String, p: &String) ->bool {
let (m, n, mut i, mut j) = (p.len(), q.len(), 0, 0);
while i < n {
if j == m && q.chars().nth(i).unwrap().is_uppercase() {
return false;
}
if (j == m || p.chars().nth(j).unwrap().is_uppercase()) && q.chars().nth(i).unwrap().is_lowercase() {
i += 1;
continue;
}
let qi = q.chars().nth(i).unwrap();
let pj = p.chars().nth(j).unwrap();
if pj.is_uppercase() && qi.is_uppercase() && pj != qi {
return false;
}
if pj.is_lowercase() && pj != qi {
i += 1;
continue;
}
i+= 1; j += 1;
}
return i == n && j == m;
}

pub fn camel_match(queries: Vec<String>, pattern: String) -> Vec<bool> {
let mut ans = Vec::new();
for q in &queries {
ans.push(Self::try_match(q, &pattern));
}
return ans;
}
}