MCPcopy Create free account
hub / github.com/Ainevsia/Leetcode-Rust / four_sum

Method four_sum

18. 4Sum/src/main.rs:9–19  ·  view source on GitHub ↗

this function owns the nums and ret

(mut nums: Vec<i32>, target: i32)

Source from the content-addressed store, hash-verified

7impl Solution {
8 /// this function owns the nums and ret
9 pub fn four_sum(mut nums: Vec<i32>, target: i32) -> Vec<Vec<i32>> {
10 if nums.len() < 4 { return vec![] }
11 nums.sort();
12 println!("nums = {:?}", nums);
13 let mut ret = vec![];
14 for i in 0..nums.len() - 3 {
15 if i > 0 && nums[i - 1] == nums[i] { continue }
16 Self::three_sum(nums[i], &nums[i + 1..nums.len()], target, &mut ret);
17 }
18 ret
19 }
20
21 /// implement the default O(n^2) three sum
22 /// nums must be at least 3 element long

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected