Skip to content

Commit 320fcb5

Browse files
authored
feat: add php solution to lc problem: No.1748 (doocs#981)
1 parent 0e52e8c commit 320fcb5

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

solution/1700-1799/1748.Sum of Unique Elements/README.md

+20
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,26 @@ impl Solution {
188188
}
189189
```
190190

191+
### **PHP**
192+
193+
```php
194+
class Solution {
195+
/**
196+
* @param Integer[] $nums
197+
* @return Integer
198+
*/
199+
function sumOfUnique($nums) {
200+
$sum = 0;
201+
for ($i = 0; $i < count($nums); $i++) {
202+
$hashtable[$nums[$i]] += 1;
203+
if ($hashtable[$nums[$i]] == 1) $sum += $nums[$i];
204+
if ($hashtable[$nums[$i]] == 2) $sum -= $nums[$i];
205+
}
206+
return $sum;
207+
}
208+
}
209+
```
210+
191211
### **...**
192212

193213
```

solution/1700-1799/1748.Sum of Unique Elements/README_EN.md

+20
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,26 @@ impl Solution {
173173
}
174174
```
175175

176+
### **PHP**
177+
178+
```php
179+
class Solution {
180+
/**
181+
* @param Integer[] $nums
182+
* @return Integer
183+
*/
184+
function sumOfUnique($nums) {
185+
$sum = 0;
186+
for ($i = 0; $i < count($nums); $i++) {
187+
$hashtable[$nums[$i]] += 1;
188+
if ($hashtable[$nums[$i]] == 1) $sum += $nums[$i];
189+
if ($hashtable[$nums[$i]] == 2) $sum -= $nums[$i];
190+
}
191+
return $sum;
192+
}
193+
}
194+
```
195+
176196
### **...**
177197

178198
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
/**
3+
* @param Integer[] $nums
4+
* @return Integer
5+
*/
6+
function sumOfUnique($nums) {
7+
$sum = 0;
8+
for ($i = 0; $i < count($nums); $i++) {
9+
$hashtable[$nums[$i]] += 1;
10+
if ($hashtable[$nums[$i]] == 1) $sum += $nums[$i];
11+
if ($hashtable[$nums[$i]] == 2) $sum -= $nums[$i];
12+
}
13+
return $sum;
14+
}
15+
}

0 commit comments

Comments
 (0)