Add tests, remove main in ThreeSumProblem (#5781)

This commit is contained in:
Hardik Pawar
2024-10-14 23:26:05 +05:30
committed by GitHub
parent 1dfa2e571b
commit 6ef1f7ca01
3 changed files with 53 additions and 19 deletions

View File

@ -7,29 +7,10 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
public class ThreeSumProblem {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.print("Enter the target sum ");
int ts = scan.nextInt();
System.out.print("Enter the number of elements in the array ");
int n = scan.nextInt();
System.out.println("Enter all your array elements:");
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = scan.nextInt();
}
ThreeSumProblem th = new ThreeSumProblem();
System.out.println("Brute Force Approach\n" + (th.bruteForce(arr, ts)) + "\n");
System.out.println("Two Pointer Approach\n" + (th.twoPointer(arr, ts)) + "\n");
System.out.println("Hashmap Approach\n" + (th.hashMap(arr, ts)));
scan.close();
}
public List<List<Integer>> bruteForce(int[] nums, int target) {
List<List<Integer>> arr = new ArrayList<List<Integer>>();