diff --git a/rs/largest-positive-integer-that-exists-with-its-negative.rs b/rs/largest-positive-integer-that-exists-with-its-negative.rs new file mode 100644 index 0000000..e8b8b89 --- /dev/null +++ b/rs/largest-positive-integer-that-exists-with-its-negative.rs @@ -0,0 +1,19 @@ +use std::cmp; +use std::collections::HashSet; + +impl Solution { + pub fn find_max_k(nums: Vec) -> i32 { + let mut seen = HashSet::::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 + } +}