Skip to content

Commit ce85b9a

Browse files
authored
feat: add php solution to lc problem: No.0219 (#1054)
1 parent ea81218 commit ce85b9a

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed

solution/0200-0299/0219.Contains Duplicate II/README.md

+26
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,32 @@ function containsNearbyDuplicate(nums: number[], k: number): boolean {
155155
}
156156
```
157157

158+
### **PHP**
159+
160+
```php
161+
class Solution {
162+
/**
163+
* @param Integer[] $nums
164+
* @param Integer $k
165+
* @return Boolean
166+
*/
167+
function containsNearbyDuplicate($nums, $k) {
168+
$hashtable = [];
169+
for ($i = 0; $i < count($nums); $i++) {
170+
$tmp = $nums[$i];
171+
if (
172+
array_key_exists($tmp, $hashtable) &&
173+
$k >= $i - $hashtable[$tmp]
174+
) {
175+
return true;
176+
}
177+
$hashtable[$tmp] = $i;
178+
}
179+
return false;
180+
}
181+
}
182+
```
183+
158184
### **...**
159185

160186
```

solution/0200-0299/0219.Contains Duplicate II/README_EN.md

+26
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,32 @@ function containsNearbyDuplicate(nums: number[], k: number): boolean {
146146
}
147147
```
148148

149+
### **PHP**
150+
151+
```php
152+
class Solution {
153+
/**
154+
* @param Integer[] $nums
155+
* @param Integer $k
156+
* @return Boolean
157+
*/
158+
function containsNearbyDuplicate($nums, $k) {
159+
$hashtable = [];
160+
for ($i = 0; $i < count($nums); $i++) {
161+
$tmp = $nums[$i];
162+
if (
163+
array_key_exists($tmp, $hashtable) &&
164+
$k >= $i - $hashtable[$tmp]
165+
) {
166+
return true;
167+
}
168+
$hashtable[$tmp] = $i;
169+
}
170+
return false;
171+
}
172+
}
173+
```
174+
149175
### **...**
150176

151177
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution {
2+
/**
3+
* @param Integer[] $nums
4+
* @param Integer $k
5+
* @return Boolean
6+
*/
7+
function containsNearbyDuplicate($nums, $k) {
8+
$hashtable = [];
9+
for ($i = 0; $i < count($nums); $i++) {
10+
$tmp = $nums[$i];
11+
if (
12+
array_key_exists($tmp, $hashtable) &&
13+
$k >= $i - $hashtable[$tmp]
14+
) {
15+
return true;
16+
}
17+
$hashtable[$tmp] = $i;
18+
}
19+
return false;
20+
}
21+
}

0 commit comments

Comments
 (0)