Skip to content

Commit f0dd82e

Browse files
authoredJan 18, 2021
[LeetCode] Add January 18.
1 parent 3037205 commit f0dd82e

File tree

1 file changed

+16
-0
lines changed
  • solved/LeetCode/Challenges/2020/January

1 file changed

+16
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
fun maxOperations(nums: IntArray, k: Int): Int {
3+
val freq = mutableMapOf<Int, Int>()
4+
var ans = 0
5+
for (i in nums) {
6+
val target = k - i
7+
if ((freq[target] ?: 0) > 0) {
8+
freq.put(target, freq[target]!! -1)
9+
ans++
10+
} else {
11+
freq[i] = (freq[i] ?: 0) + 1
12+
}
13+
}
14+
return ans
15+
}
16+
}

0 commit comments

Comments
 (0)
Failed to load comments.