1679. Max Number of K-Sum Pairs Medium
1/**
2 * [1679] Max Number of K-Sum Pairs
3 *
4 * You are given an integer array nums and an integer k.
5 * In one operation, you can pick two numbers from the array whose sum equals k and remove them from the array.
6 * Return the maximum number of operations you can perform on the array.
7 *
8 * Example 1:
9 *
10 * Input: nums = [1,2,3,4], k = 5
11 * Output: 2
12 * Explanation: Starting with nums = [1,2,3,4]:
13 * - Remove numbers 1 and 4, then nums = [2,3]
14 * - Remove numbers 2 and 3, then nums = []
15 * There are no more pairs that sum up to 5, hence a total of 2 operations.
16 * Example 2:
17 *
18 * Input: nums = [3,1,3,4,3], k = 6
19 * Output: 1
20 * Explanation: Starting with nums = [3,1,3,4,3]:
21 * - Remove the first two 3's, then nums = [1,4,3]
22 * There are no more pairs that sum up to 6, hence a total of 1 operation.
23 *
24 * Constraints:
25 *
26 * 1 <= nums.length <= 10^5
27 * 1 <= nums[i] <= 10^9
28 * 1 <= k <= 10^9
29 *
30 */
31pub struct Solution {}
32
33// problem: https://leetcode.com/problems/max-number-of-k-sum-pairs/
34// discuss: https://leetcode.com/problems/max-number-of-k-sum-pairs/discuss/?currentPage=1&orderBy=most_votes&query=
35
36// submission codes start here
37
38impl Solution {
39 pub fn max_operations(nums: Vec<i32>, k: i32) -> i32 {
40 0
41 }
42}
43
44// submission codes end
45
46#[cfg(test)]
47mod tests {
48 use super::*;
49
50 #[test]
51 fn test_1679() {
52 }
53}
54
Back
© 2025 bowen.ge All Rights Reserved.