Skip to content

Commit 281349f

Browse files
committed
Sync LeetCode submission - Two Sum (rust)
1 parent b96a3cf commit 281349f

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed
Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,14 @@
11
impl Solution {
22
pub fn two_sum(nums: Vec<i32>, target: i32) -> Vec<i32> {
3-
let mut ret: Vec<i32> = Vec::new();
4-
let numbers: Vec<i32> = nums;
5-
let mut i = 0;
6-
let mut j = 0;
7-
8-
for value in &numbers {
9-
for secondval in &numbers {
10-
if value + secondval == target && i != j {
11-
ret.push(i);
12-
ret.push(j);
13-
return ret
14-
}
15-
j += 1;
3+
for i in 0..nums.len() {
4+
for j in 0..nums.len() {
5+
if nums[i] + nums[j] == target && i != j {
6+
return vec![i as i32, j as i32]
7+
}
168
}
17-
i += 1;
18-
j = 0;
199
}
20-
return vec![1,2]
10+
11+
unreachable!()
2112
}
13+
2214
}

0 commit comments

Comments
 (0)