Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 04045d7

Browse files
committed
Add solution 44.
1 parent 6050c2e commit 04045d7

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
class Solution {
2+
3+
/**
4+
* @param String $s
5+
* @param String $p
6+
* @return Boolean
7+
*/
8+
function isMatch($s, $p) {
9+
$dp = array_fill(0, strlen($p) + 1, array_fill(0, strlen($s) + 1, 0));
10+
$dp[0][0] = 1;
11+
for ($i = 0; $i < strlen($p); $i++) {
12+
if ($p[$i] == '?') {
13+
for ($j = 0; $j < strlen($s); $j++) {
14+
if ($dp[$i][$j] == 1)
15+
$dp[$i + 1][$j + 1] = 1;
16+
}
17+
} else if ($p[$i] == '*') {
18+
$a = 0;
19+
for ($j = 0; $j < count($dp[$i]); $j++) {
20+
if ($dp[$i][$j] == 1) $a = 1;
21+
$dp[$i + 1][$j] = $a;
22+
}
23+
} else {
24+
for ($j = 0; $j < strlen($s); $j++) {
25+
if ($dp[$i][$j] == 1 && $p[$i] == $s[$j])
26+
$dp[$i + 1][$j + 1] = 1;
27+
}
28+
}
29+
}
30+
return $dp[strlen($p)][strlen($s)] == 1;
31+
}
32+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /