Skip to content

Commit 1604e27

Browse files
authored
feat: add php solution to lc problem: No.0383 (doocs#954)
1 parent ec44267 commit 1604e27

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

solution/0300-0399/0383.Ransom Note/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,29 @@ func canConstruct(ransomNote string, magazine string) bool {
147147
}
148148
```
149149

150+
### **PHP**
151+
152+
```php
153+
class Solution {
154+
/**
155+
* @param String $ransomNote
156+
* @param String $magazine
157+
* @return Boolean
158+
*/
159+
function canConstruct($ransomNote, $magazine) {
160+
$arrM = str_split($magazine);
161+
for ($i = 0; $i < strlen($magazine); $i++) {
162+
$hashtable[$arrM[$i]] += 1;
163+
}
164+
for ($j = 0; $j < strlen($ransomNote); $j++) {
165+
if (!isset($hashtable[$ransomNote[$j]]) || $hashtable[$ransomNote[$j]] == 0) return false;
166+
else $hashtable[$ransomNote[$j]] -= 1;
167+
}
168+
return true;
169+
}
170+
}
171+
```
172+
150173
### **...**
151174

152175
```

solution/0300-0399/0383.Ransom Note/README_EN.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,29 @@ func canConstruct(ransomNote string, magazine string) bool {
122122
}
123123
```
124124

125+
### **PHP**
126+
127+
```php
128+
class Solution {
129+
/**
130+
* @param String $ransomNote
131+
* @param String $magazine
132+
* @return Boolean
133+
*/
134+
function canConstruct($ransomNote, $magazine) {
135+
$arrM = str_split($magazine);
136+
for ($i = 0; $i < strlen($magazine); $i++) {
137+
$hashtable[$arrM[$i]] += 1;
138+
}
139+
for ($j = 0; $j < strlen($ransomNote); $j++) {
140+
if (!isset($hashtable[$ransomNote[$j]]) || $hashtable[$ransomNote[$j]] == 0) return false;
141+
else $hashtable[$ransomNote[$j]] -= 1;
142+
}
143+
return true;
144+
}
145+
}
146+
```
147+
125148
### **...**
126149

127150
```
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
/**
3+
* @param String $ransomNote
4+
* @param String $magazine
5+
* @return Boolean
6+
*/
7+
function canConstruct($ransomNote, $magazine) {
8+
$arrM = str_split($magazine);
9+
for ($i = 0; $i < strlen($magazine); $i++) {
10+
$hashtable[$arrM[$i]] += 1;
11+
}
12+
for ($j = 0; $j < strlen($ransomNote); $j++) {
13+
if (!isset($hashtable[$ransomNote[$j]]) || $hashtable[$ransomNote[$j]] == 0) return false;
14+
else $hashtable[$ransomNote[$j]] -= 1;
15+
}
16+
return true;
17+
}
18+
}

0 commit comments

Comments
 (0)