Skip to content

Commit

Permalink
[LeetCode] Add January 18.
Browse files Browse the repository at this point in the history
  • Loading branch information
pin3da authored Jan 18, 2021
1 parent 3037205 commit f0dd82e
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions solved/LeetCode/Challenges/2020/January/18.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Solution {
fun maxOperations(nums: IntArray, k: Int): Int {
val freq = mutableMapOf<Int, Int>()
var ans = 0
for (i in nums) {
val target = k - i
if ((freq[target] ?: 0) > 0) {
freq.put(target, freq[target]!! -1)
ans++
} else {
freq[i] = (freq[i] ?: 0) + 1
}
}
return ans
}
}

0 comments on commit f0dd82e

Please sign in to comment.