Skip to content

Commit 50297c4

Browse files
authored
feat: add rust solution to lc problem: No.2441 (doocs#1364)
Signed-off-by: xiaolatiao <1628652790@qq.com>
1 parent ed27f66 commit 50297c4

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

solution/2400-2499/2441.Largest Positive Integer That Exists With Its Negative/README.md

+23
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,29 @@ impl Solution {
164164
}
165165
```
166166

167+
```rust
168+
use std::collections::HashSet;
169+
170+
impl Solution {
171+
pub fn find_max_k(nums: Vec<i32>) -> i32 {
172+
let mut ans = -1;
173+
let mut h = HashSet::new();
174+
175+
for &n in &nums {
176+
h.insert(n);
177+
}
178+
179+
for &n in &nums {
180+
if h.contains(&-n) && n > ans {
181+
ans = n;
182+
}
183+
}
184+
185+
ans
186+
}
187+
}
188+
```
189+
167190
### **...**
168191

169192
```

solution/2400-2499/2441.Largest Positive Integer That Exists With Its Negative/README_EN.md

+23
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,29 @@ impl Solution {
144144
}
145145
```
146146

147+
```rust
148+
use std::collections::HashSet;
149+
150+
impl Solution {
151+
pub fn find_max_k(nums: Vec<i32>) -> i32 {
152+
let mut ans = -1;
153+
let mut h = HashSet::new();
154+
155+
for &n in &nums {
156+
h.insert(n);
157+
}
158+
159+
for &n in &nums {
160+
if h.contains(&-n) && n > ans {
161+
ans = n;
162+
}
163+
}
164+
165+
ans
166+
}
167+
}
168+
```
169+
147170
### **...**
148171

149172
```

0 commit comments

Comments
 (0)