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 ced9f63

Browse files
authored
feat: add php solution to lc problem: No.0299 (doocs#966)
1 parent 0d13b1e commit ced9f63

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed

‎solution/0200-0299/0299.Bulls and Cows/README.md‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,34 @@ func min(a, b int) int {
163163
}
164164
```
165165

166+
### **PHP**
167+
168+
```php
169+
class Solution {
170+
/**
171+
* @param String $secret
172+
* @param String $guess
173+
* @return String
174+
*/
175+
function getHint($secret, $guess) {
176+
$cntA = 0;
177+
$cntB = 0;
178+
$len = strlen($secret);
179+
for ($i = 0; $i < $len; $i++) {
180+
if ($secret[$i] == $guess[$i]) $cntA++;
181+
else $hashtable[$secret[$i]] += 1;
182+
}
183+
for ($i = 0; $i < $len; $i++) {
184+
if ($secret[$i] != $guess[$i] && $hashtable[$guess[$i]] > 0) {
185+
$cntB++;
186+
$hashtable[$guess[$i]] -= 1;
187+
}
188+
}
189+
return $cntA."A".$cntB."B";
190+
}
191+
}
192+
```
193+
166194
### **...**
167195

168196
```

‎solution/0200-0299/0299.Bulls and Cows/README_EN.md‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,34 @@ func min(a, b int) int {
152152
}
153153
```
154154

155+
### **PHP**
156+
157+
```php
158+
class Solution {
159+
/**
160+
* @param String $secret
161+
* @param String $guess
162+
* @return String
163+
*/
164+
function getHint($secret, $guess) {
165+
$cntA = 0;
166+
$cntB = 0;
167+
$len = strlen($secret);
168+
for ($i = 0; $i < $len; $i++) {
169+
if ($secret[$i] == $guess[$i]) $cntA++;
170+
else $hashtable[$secret[$i]] += 1;
171+
}
172+
for ($i = 0; $i < $len; $i++) {
173+
if ($secret[$i] != $guess[$i] && $hashtable[$guess[$i]] > 0) {
174+
$cntB++;
175+
$hashtable[$guess[$i]] -= 1;
176+
}
177+
}
178+
return $cntA."A".$cntB."B";
179+
}
180+
}
181+
```
182+
155183
### **...**
156184

157185
```
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution {
2+
/**
3+
* @param String $secret
4+
* @param String $guess
5+
* @return String
6+
*/
7+
function getHint($secret, $guess) {
8+
$cntA = 0;
9+
$cntB = 0;
10+
$len = strlen($secret);
11+
for ($i = 0; $i < $len; $i++) {
12+
if ($secret[$i] == $guess[$i]) $cntA++;
13+
else $hashtable[$secret[$i]] += 1;
14+
}
15+
for ($i = 0; $i < $len; $i++) {
16+
if ($secret[$i] != $guess[$i] && $hashtable[$guess[$i]] > 0) {
17+
$cntB++;
18+
$hashtable[$guess[$i]] -= 1;
19+
}
20+
}
21+
return $cntA."A".$cntB."B";
22+
}
23+
}

0 commit comments

Comments
(0)

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