Skip to content

Commit 60ab030

Browse files
add 1679
1 parent af23b0b commit 60ab030

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|1679|[Max Number of K-Sum Pairs](https://leetcode.com/problems/max-number-of-k-sum-pairs/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1679.java) ||Medium|HashTable|
1112
|1678|[Goal Parser Interpretation](https://leetcode.com/problems/goal-parser-interpretation/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1678.java) ||Easy|String|
1213
|1673|[Find the Most Competitive Subsequence](https://leetcode.com/problems/find-the-most-competitive-subsequence/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1673.java) ||Medium|Stack, Greedy|
1314
|1672|[Richest Customer Wealth](https://leetcode.com/problems/richest-customer-wealth/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1672.java) ||Easy|Array|
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
6+
public class _1679 {
7+
public static class Solution1 {
8+
public int maxOperations(int[] nums, int k) {
9+
Map<Integer, Integer> map = new HashMap<>();
10+
int ops = 0;
11+
for (int num : nums) {
12+
if (map.containsKey(k - num)) {
13+
map.put(k - num, map.get(k - num) - 1);
14+
ops++;
15+
if (map.get(k - num) == 0) {
16+
map.remove(k - num);
17+
}
18+
} else {
19+
map.put(num, map.getOrDefault(num, 0) + 1);
20+
}
21+
}
22+
return ops;
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)