Skip to content

Commit

Permalink
add 1748
Browse files Browse the repository at this point in the history
  • Loading branch information
fishercoder1534 committed Feb 6, 2021
1 parent 8d3dde8 commit 5cbd633
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ _If you like this project, please leave me a star._ ★
| # | Title | Solutions | Video | Difficulty | Tag
|-----|----------------|---------------|--------|-------------|-------------
|1749|[Maximum Absolute Sum of Any Subarray](https://leetcode.com/problems/maximum-absolute-sum-of-any-subarray/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1749.java) ||Medium|Greedy|
|1748|[Sum of Unique Elements](https://leetcode.com/problems/sum-of-unique-elements/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1748.java) ||Easy|Array, HashTable|
|1745|[Palindrome Partitioning IV](https://leetcode.com/problems/palindrome-partitioning-iv/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1745.java) ||Hard|String, DP|
|1743|[Restore the Array From Adjacent Pairs](https://leetcode.com/problems/restore-the-array-from-adjacent-pairs/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1743.java) ||Medium|Greedy|
|1742|[Maximum Number of Balls in a Box](https://leetcode.com/problems/maximum-number-of-balls-in-a-box/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1742.java) ||Easy|Array|
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/com/fishercoder/solutions/_1748.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.fishercoder.solutions;

import java.util.HashMap;
import java.util.Map;

public class _1748 {
public static class Solution1 {
public int sumOfUnique(int[] nums) {
Map<Integer, Integer> map = new HashMap<>();
int sum = 0;
for (int num : nums) {
map.put(num, map.getOrDefault(num, 0) + 1);
}
for (int num : map.keySet()) {
if (map.get(num) == 1) {
sum += num;
}
}
return sum;
}
}
}

0 comments on commit 5cbd633

Please sign in to comment.