-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
47 lines (41 loc) · 2.18 KB
/
Copy pathMain.java
File metadata and controls
47 lines (41 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import java.util.*;
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
public class Main {
public static void main(String[] args) {
// BubbleSort sSort = new BubbleSort();
ArrayList<Integer> list = new aListValue().getAlist();
ArrayList<Integer> aList = new ArrayList<>(Arrays.asList(5, 8, 3, 9, 4, 1, 7));
ArrayList<Integer> bList = new ArrayList<>(Arrays.asList(-913743, 3241, 999999, 1243153, 0, 0, 999999999, 287356, -384756, 2938468, -73645, 18374, 13));
ArrayList<Integer> cList = new ArrayList<>(Arrays.asList(5, 3, 1, -10, -11, -100));
ArrayList<Integer> dList = new ArrayList<>(Arrays.asList(-1, 2, 2, -1));
ArrayList<Integer> eList = new ArrayList<>(Arrays.asList(1, 2, 3, 0, 1, 2, 0, 7, 7));
// System.out.println("bubble sort:");
// System.out.println(BubbleSort.bubble_sort(aList));
// System.out.println("merge sort returns:");
// System.out.println(Merge_Sort.merge_sort(aList));
// System.out.println("my quick sort trying to start from the beginning returns:");
// System.out.println(DivideConquerQuickSortarr.quick_sort(aList))
// System.out.println("IK quick start that puts the pivot value at the end returns:");
// System.out.println(DivideConquerQuickSortIK.quick_sort(aList));
// System.out.println(aList.size());
// System.out.println(HeapSort.heap_sort(bList));
int tar = 37;
int[] a = {21, 31, 51, -98, 74, 16};
System.out.println(Arrays.toString(twoSum(a, tar)));
//System.out.println(quick_sort.selection_sort(bList));
}
public static int[] twoSum(int[] num, int target) {
Map<Integer, Integer> map = new HashMap<>();
int index1;
int index2;
for (int i = 0; i < num.length; i++) {
int compliment = target - num[i];
if (map.containsKey(compliment)) {
return new int[]{map.get(compliment), i};
}
map.put(num[i], i);
}
throw new IllegalArgumentException("no two sum solution found");
}
}