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 8b176df

Browse files
authored
feat: add php solution to lc problem: No.1512 (#1011)
1 parent 896dc29 commit 8b176df

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

‎solution/1500-1599/1512.Number of Good Pairs/README.md‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,28 @@ int numIdenticalPairs(int *nums, int numsSize) {
254254
}
255255
```
256256

257+
### **PHP**
258+
259+
```php
260+
class Solution {
261+
/**
262+
* @param Integer[] $nums
263+
* @return Integer
264+
*/
265+
function numIdenticalPairs($nums) {
266+
$arr = array_values(array_unique($nums));
267+
for ($i = 0; $i < count($nums); $i++) {
268+
$v[$nums[$i]] += 1;
269+
}
270+
$rs = 0;
271+
for ($j = 0; $j < count($arr); $j++) {
272+
$rs += $v[$arr[$j]] * ($v[$arr[$j]] - 1) / 2;
273+
}
274+
return $rs;
275+
}
276+
}
277+
```
278+
257279
### **...**
258280

259281
```

‎solution/1500-1599/1512.Number of Good Pairs/README_EN.md‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,28 @@ int numIdenticalPairs(int *nums, int numsSize) {
240240
}
241241
```
242242

243+
### **PHP**
244+
245+
```php
246+
class Solution {
247+
/**
248+
* @param Integer[] $nums
249+
* @return Integer
250+
*/
251+
function numIdenticalPairs($nums) {
252+
$arr = array_values(array_unique($nums));
253+
for ($i = 0; $i < count($nums); $i++) {
254+
$v[$nums[$i]] += 1;
255+
}
256+
$rs = 0;
257+
for ($j = 0; $j < count($arr); $j++) {
258+
$rs += $v[$arr[$j]] * ($v[$arr[$j]] - 1) / 2;
259+
}
260+
return $rs;
261+
}
262+
}
263+
```
264+
243265
### **...**
244266

245267
```
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[] $nums
4+
* @return Integer
5+
*/
6+
function numIdenticalPairs($nums) {
7+
$arr = array_values(array_unique($nums));
8+
for ($i = 0; $i < count($nums); $i++) {
9+
$v[$nums[$i]] += 1;
10+
}
11+
$rs = 0;
12+
for ($j = 0; $j < count($arr); $j++) {
13+
$rs += $v[$arr[$j]] * ($v[$arr[$j]] - 1) / 2;
14+
}
15+
return $rs;
16+
}
17+
}

0 commit comments

Comments
(0)

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