2441. Largest Positive Integer That Exists With Its Negative Easy
1/**
2 * [2441] Largest Positive Integer That Exists With Its Negative
3 *
4 * Given an integer array nums that does not contain any zeros, find the largest positive integer k such that -k also exists in the array.
5 * Return the positive integer k. If there is no such integer, return -1.
6 *
7 * <strong class="example">Example 1:
8 *
9 * Input: nums = [-1,2,-3,3]
10 * Output: 3
11 * Explanation: 3 is the only valid k we can find in the array.
12 *
13 * <strong class="example">Example 2:
14 *
15 * Input: nums = [-1,10,6,7,-7,1]
16 * Output: 7
17 * Explanation: Both 1 and 7 have their corresponding negative values in the array. 7 has a larger value.
18 *
19 * <strong class="example">Example 3:
20 *
21 * Input: nums = [-10,8,6,7,-2,-3]
22 * Output: -1
23 * Explanation: There is no a single valid k, we return -1.
24 *
25 *
26 * Constraints:
27 *
28 * 1 <= nums.length <= 1000
29 * -1000 <= nums[i] <= 1000
30 * nums[i] != 0
31 *
32 */
33pub struct Solution {}
34
35// problem: https://leetcode.com/problems/largest-positive-integer-that-exists-with-its-negative/
36// discuss: https://leetcode.com/problems/largest-positive-integer-that-exists-with-its-negative/discuss/?currentPage=1&orderBy=most_votes&query=
37
38// submission codes start here
39
40impl Solution {
41 pub fn find_max_k(nums: Vec<i32>) -> i32 {
42 0
43 }
44}
45
46// submission codes end
47
48#[cfg(test)]
49mod tests {
50 use super::*;
51
52 #[test]
53 fn test_2441() {
54 }
55}
56
Back
© 2025 bowen.ge All Rights Reserved.