We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b96a3cf commit 281349fCopy full SHA for 281349f
my-folder/problems/two_sum/solution.rs
@@ -1,22 +1,14 @@
1
impl Solution {
2
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;
+ for i in 0..nums.len() {
+ for j in 0..nums.len() {
+ if nums[i] + nums[j] == target && i != j {
+ return vec![i as i32, j as i32]
+ }
16
}
17
- i += 1;
18
- j = 0;
19
20
- return vec![1,2]
+
+ unreachable!()
21
22
0 commit comments