diff --git a/solved/LeetCode/Challenges/2020/January/18.kt b/solved/LeetCode/Challenges/2020/January/18.kt new file mode 100644 index 00000000..c0ca9630 --- /dev/null +++ b/solved/LeetCode/Challenges/2020/January/18.kt @@ -0,0 +1,16 @@ +class Solution { + fun maxOperations(nums: IntArray, k: Int): Int { + val freq = mutableMapOf() + 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 + } +}