File tree 3 files changed +79
-0
lines changed
solution/0200-0299/0299.Bulls and Cows
3 files changed +79
-0
lines changed Original file line number Diff line number Diff line change @@ -163,6 +163,34 @@ func min(a, b int) int {
163
163
}
164
164
```
165
165
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
+
166
194
### ** ...**
167
195
168
196
```
Original file line number Diff line number Diff line change @@ -152,6 +152,34 @@ func min(a, b int) int {
152
152
}
153
153
```
154
154
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
+
155
183
### ** ...**
156
184
157
185
```
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments