Skip to content

Commit 7ab0647

Browse files
authored
feat: add php solution to lc problem: No.1056 (doocs#1034)
1 parent 20a8332 commit 7ab0647

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

solution/1000-1099/1056.Confusing Number/README.md

+25
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,31 @@ func confusingNumber(n int) bool {
159159
}
160160
```
161161

162+
### **PHP**
163+
164+
```php
165+
class Solution {
166+
/**
167+
* @param Integer $n
168+
* @return Boolean
169+
*/
170+
function confusingNumber($n) {
171+
$d = [0, 1, -1, -1, -1, -1, 9, -1, 8, 6];
172+
$x = $n;
173+
$y = 0;
174+
while ($x > 0) {
175+
$v = $x % 10;
176+
if ($d[$v] < 0) {
177+
return false;
178+
}
179+
$y = $y * 10 + $d[$v];
180+
$x = intval($x / 10);
181+
}
182+
return $y != $n;
183+
}
184+
}
185+
```
186+
162187
### **...**
163188

164189
```

solution/1000-1099/1056.Confusing Number/README_EN.md

+25
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,31 @@ func confusingNumber(n int) bool {
131131
}
132132
```
133133

134+
### **PHP**
135+
136+
```php
137+
class Solution {
138+
/**
139+
* @param Integer $n
140+
* @return Boolean
141+
*/
142+
function confusingNumber($n) {
143+
$d = [0, 1, -1, -1, -1, -1, 9, -1, 8, 6];
144+
$x = $n;
145+
$y = 0;
146+
while ($x > 0) {
147+
$v = $x % 10;
148+
if ($d[$v] < 0) {
149+
return false;
150+
}
151+
$y = $y * 10 + $d[$v];
152+
$x = intval($x / 10);
153+
}
154+
return $y != $n;
155+
}
156+
}
157+
```
158+
134159
### **...**
135160

136161
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution {
2+
/**
3+
* @param Integer $n
4+
* @return Boolean
5+
*/
6+
function confusingNumber($n) {
7+
$d = [0, 1, -1, -1, -1, -1, 9, -1, 8, 6];
8+
$x = $n;
9+
$y = 0;
10+
while ($x > 0) {
11+
$v = $x % 10;
12+
if ($d[$v] < 0) {
13+
return false;
14+
}
15+
$y = $y * 10 + $d[$v];
16+
$x = intval($x / 10);
17+
}
18+
return $y != $n;
19+
}
20+
}

0 commit comments

Comments
 (0)