Skip to content

Commit 9081052

Browse files
committed
comment
1 parent b6559b0 commit 9081052

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

src/array/best_time_to_buy_and_sell_stock.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ where
2020
P: IntoIterator<Item = i32> + Copy,
2121
{
2222
let mut profit = 0;
23-
// slightly more elegant than setting to el[0] and starting loop at 1
23+
// opinion: slightly more elegant than setting to el[0] and starting loop at 1
2424
let mut current_min = i32::MAX;
2525
for i in prices.into_iter() {
2626
profit = profit.max(i - current_min);

src/array/three_sum.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,33 @@ Constraints:
1414
-10^5 <= nums[i] <= 10^5
1515
*/
1616

17+
use std::collections::HashSet;
18+
1719
/*
1820
Naive solution
1921
T: O(N^3)
2022
S: O(N)
2123
*/
22-
pub fn solution_a(_nums: Vec<i32>) -> Vec<Vec<i32>> {
23-
vec![]
24+
pub fn solution_a(nums: Vec<i32>) -> Vec<Vec<i32>> {
25+
let mut res: Vec<Vec<i32>> = Vec::new();
26+
27+
for (i, x) in nums.iter().enumerate() {
28+
for (j, y) in nums.iter().enumerate().skip(i + 1) {
29+
for (_, z) in nums.iter().enumerate().skip(j + 1) {
30+
let sum = x + y + z;
31+
if sum != 0 {
32+
continue;
33+
}
34+
35+
let mut v = vec![x.clone(), y.clone(), z.clone()];
36+
v.sort();
37+
res.push(v);
38+
}
39+
}
40+
}
41+
42+
res.dedup();
43+
res
2444
}
2545

2646
/*

0 commit comments

Comments
 (0)