Skip to main content

three_sum

Function three_sum 

Source
pub fn three_sum(list: &[i32]) -> Result<HashSet<(i32, i32, i32)>, String>
Expand description

Given an array of integers, find all unique triplets that sum to zero using the two-pointer technique.

Takes a list reference as an input and returns a HashSet<(i32,i32,i32)> or an error explaining the problem

ยงExamples

Basic usage:

let result = algorithmz::array::three_sum(&[-1, 0, 1, 2, -1, -4]).unwrap();
assert_eq!(result,std::collections::HashSet::from([(-1, 0, 1), (-1, -1, 2)]));

Match example:

use algorithmz::array::three_sum;
match three_sum(&[-1, 0, 1, 2, -1, -4]) {
    Ok(n) => println!("The result was: {:?}",n),
    Err(e) => eprintln!("The error was: {}",e),
}