File tree 3 files changed +55
-0
lines changed
solution/1700-1799/1748.Sum of Unique Elements
3 files changed +55
-0
lines changed Original file line number Diff line number Diff line change @@ -188,6 +188,26 @@ impl Solution {
188
188
}
189
189
```
190
190
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
+
191
211
### ** ...**
192
212
193
213
```
Original file line number Diff line number Diff line change @@ -173,6 +173,26 @@ impl Solution {
173
173
}
174
174
```
175
175
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
+
176
196
### ** ...**
177
197
178
198
```
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments