mirror of
https://gitlab.com/mfocko/LeetCode.git
synced 2024-11-14 09:59:41 +01:00
20 lines
372 B
Rust
20 lines
372 B
Rust
|
use std::cmp;
|
||
|
use std::collections::HashSet;
|
||
|
|
||
|
impl Solution {
|
||
|
pub fn find_max_k(nums: Vec<i32>) -> i32 {
|
||
|
let mut seen = HashSet::<i32>::new();
|
||
|
|
||
|
let mut max_k = -1;
|
||
|
for x in &nums {
|
||
|
if seen.contains(&-x) {
|
||
|
max_k = cmp::max(max_k, x.abs());
|
||
|
}
|
||
|
|
||
|
seen.insert(*x);
|
||
|
}
|
||
|
|
||
|
max_k
|
||
|
}
|
||
|
}
|