@Test(expected = IllegalArgumentException.class) public void shouldNotAcceptNullArraysLinear() { findSums.findLinearComplexityOrder(null, 2); }
public List<Pair<Integer, Integer>> findLinearComplexityOrder(int[] numbers, int n) { validateInput(numbers); List<Pair<Integer, Integer>> sums = new LinkedList<Pair<Integer, Integer>>(); Map<Integer, Integer> partialElements = new HashMap<Integer, Integer>(); for (int number : numbers) { if (partialElements.containsKey(number)) { sums.add(new Pair<Integer, Integer>(number, partialElements.get(number))); } else { partialElements.put(n - number, number); } } return sums; }
FindSums { public List<Pair<Integer, Integer>> findLinearComplexityOrder(int[] numbers, int n) { validateInput(numbers); List<Pair<Integer, Integer>> sums = new LinkedList<Pair<Integer, Integer>>(); Map<Integer, Integer> partialElements = new HashMap<Integer, Integer>(); for (int number : numbers) { if (partialElements.containsKey(number)) { sums.add(new Pair<Integer, Integer>(number, partialElements.get(number))); } else { partialElements.put(n - number, number); } } return sums; } }
FindSums { public List<Pair<Integer, Integer>> findLinearComplexityOrder(int[] numbers, int n) { validateInput(numbers); List<Pair<Integer, Integer>> sums = new LinkedList<Pair<Integer, Integer>>(); Map<Integer, Integer> partialElements = new HashMap<Integer, Integer>(); for (int number : numbers) { if (partialElements.containsKey(number)) { sums.add(new Pair<Integer, Integer>(number, partialElements.get(number))); } else { partialElements.put(n - number, number); } } return sums; }  }
FindSums { public List<Pair<Integer, Integer>> findLinearComplexityOrder(int[] numbers, int n) { validateInput(numbers); List<Pair<Integer, Integer>> sums = new LinkedList<Pair<Integer, Integer>>(); Map<Integer, Integer> partialElements = new HashMap<Integer, Integer>(); for (int number : numbers) { if (partialElements.containsKey(number)) { sums.add(new Pair<Integer, Integer>(number, partialElements.get(number))); } else { partialElements.put(n - number, number); } } return sums; }  List<Pair<Integer, Integer>> find(int[] numbers, int value); List<Pair<Integer, Integer>> findLinearComplexityOrder(int[] numbers, int n); }
FindSums { public List<Pair<Integer, Integer>> findLinearComplexityOrder(int[] numbers, int n) { validateInput(numbers); List<Pair<Integer, Integer>> sums = new LinkedList<Pair<Integer, Integer>>(); Map<Integer, Integer> partialElements = new HashMap<Integer, Integer>(); for (int number : numbers) { if (partialElements.containsKey(number)) { sums.add(new Pair<Integer, Integer>(number, partialElements.get(number))); } else { partialElements.put(n - number, number); } } return sums; }  List<Pair<Integer, Integer>> find(int[] numbers, int value); List<Pair<Integer, Integer>> findLinearComplexityOrder(int[] numbers, int n);  }