package org.xander.katas;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class SumInArray {
    public boolean checkBruteForce(int[] nums, int sum) {
        checkArray(nums);
        for (int i = 0; i < nums.length; i++) {
            for (int j = i; j < nums.length; j++) {
                if (nums[i] + nums[j] == sum) {
                    return true;
                }
            }
        }
        return false;
    }

    public boolean checkWithMap(int[] nums, int sum) {
        checkArray(nums);
        Map<Integer, Integer> numbers = new HashMap<>();

        for (int i = 0; i < nums.length; i++) {
            if (numbers.containsKey(nums[i])) {
//                System.out.println(nums[i] + ", " + numbers.get(nums[i]));
                return true;
            } else {
                numbers.put(sum - nums[i], nums[i]);
            }
        }
        return false;
    }

    public boolean checkWithSet(int[] nums, int sum) {
        checkArray(nums);

        Arrays.sort(nums);

        for (int i = 0; i < nums.length; i++) {
            int found = Arrays.binarySearch(nums, sum - nums[i]);
            if (found > 0) {
//                System.out.println(nums[i] + ", " + nums[found]);
                return true;
            }
        }
        return false;
    }

    private void checkArray(int[] nums) {
        if (nums == null) {
            throw new NullPointerException("Array is null");
        }
        if (nums.length == 0 || nums.length == 1) {
            throw new IllegalStateException("Array length is not sufficient");
        }
    }
}

@@ -593,16 +593,47 @@
 Map%3C%3E();
+%0A        boolean found = false;
 %0A%0A      
@@ -807,38 +807,39 @@
                 
-return
+found =
  true;%0A         
@@ -935,36 +935,36 @@
         return f
-alse
+ound
 ;%0A    %7D%0A%0A    pub
@@ -1057,33 +1057,63 @@
 ays.sort(nums);%0A
+        boolean found = false;
 %0A
-
         for (int
@@ -1165,16 +1165,21 @@
 nt found
+Index
  = Array
@@ -1236,16 +1236,21 @@
 f (found
+Index
  %3E 0) %7B%0A
@@ -1325,38 +1325,39 @@
                 
-return
+found =
  true;%0A         
@@ -1379,36 +1379,36 @@
         return f
-alse
+ound
 ;%0A    %7D%0A%0A    pri

Update SumInArray.java