MCPcopy Create free account
hub / github.com/Ainevsia/Leetcode-Rust / cal

Method cal

44. Wildcard Matching/src/main.rs:98–114  ·  view source on GitHub ↗
(&mut self, i:usize, j:usize)

Source from the content-addressed store, hash-verified

96
97impl<'a> Dp<'a> {
98 pub fn cal(&mut self, i:usize, j:usize) -> i32 {
99 if self.dp[i][j] >= 0 { return self.dp[i][j] }
100 self.dp[i][j] = match (self.s[i], self.p[j]) {
101 (_, '*') => {
102 if self.cal(i, j-1) == 1 { 1 }
103 else if self.cal(i-1, j) == 1 { 1 }
104 else if self.cal(i-1, j-1) == 1 { 1 }
105 else { 0 }
106 }
107 (_, '?') => self.cal(i-1, j-1),
108 (a, b) => {
109 if a == b { self.cal(i-1, j-1) }
110 else { 0 }
111 }
112 };
113 self.dp[i][j]
114 }
115
116 pub fn new(s: &'a [char], p: &'a [char], dp: &'a mut Vec<Vec<i32>>) -> Dp<'a> {
117 Dp { s,p,dp }

Callers 1

is_match_nMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected