Skip to content

Commit 3dcc2cd

Browse files
authored
feat: add php solution to lc problem: No.1394 (#978)
1 parent 6afa941 commit 3dcc2cd

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

solution/1300-1399/1394.Find Lucky Integer in an Array/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,28 @@ func findLucky(arr []int) int {
139139
}
140140
```
141141

142+
### **PHP**
143+
144+
```php
145+
class Solution {
146+
/**
147+
* @param Integer[] $arr
148+
* @return Integer
149+
*/
150+
function findLucky($arr) {
151+
$max = -1;
152+
for ($i = 0; $i < count($arr); $i++) {
153+
$hashtable[$arr[$i]] += 1;
154+
}
155+
$keys = array_keys($hashtable);
156+
for ($j = 0; $j < count($keys); $j++) {
157+
if ($hashtable[$keys[$j]] == $keys[$j]) $max = max($max, $keys[$j]);
158+
}
159+
return $max;
160+
}
161+
}
162+
```
163+
142164
### **...**
143165

144166
```

solution/1300-1399/1394.Find Lucky Integer in an Array/README_EN.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,28 @@ func findLucky(arr []int) int {
115115
}
116116
```
117117

118+
### **PHP**
119+
120+
```php
121+
class Solution {
122+
/**
123+
* @param Integer[] $arr
124+
* @return Integer
125+
*/
126+
function findLucky($arr) {
127+
$max = -1;
128+
for ($i = 0; $i < count($arr); $i++) {
129+
$hashtable[$arr[$i]] += 1;
130+
}
131+
$keys = array_keys($hashtable);
132+
for ($j = 0; $j < count($keys); $j++) {
133+
if ($hashtable[$keys[$j]] == $keys[$j]) $max = max($max, $keys[$j]);
134+
}
135+
return $max;
136+
}
137+
}
138+
```
139+
118140
### **...**
119141

120142
```
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
/**
3+
* @param Integer[] $arr
4+
* @return Integer
5+
*/
6+
function findLucky($arr) {
7+
$max = -1;
8+
for ($i = 0; $i < count($arr); $i++) {
9+
$hashtable[$arr[$i]] += 1;
10+
}
11+
$keys = array_keys($hashtable);
12+
for ($j = 0; $j < count($keys); $j++) {
13+
if ($hashtable[$keys[$j]] == $keys[$j]) $max = max($max, $keys[$j]);
14+
}
15+
return $max;
16+
}
17+
}

0 commit comments

Comments
 (0)