class Algorithmable::Cups::TwoSum::Logarithmic

public class Solution {

  public int[] twoSum(int[] numbers, int target) {
        HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
        int[] result = new int[2];

      for (int i = 0; i < numbers.length; i++) {
              if (map.containsKey(numbers[i])) {
                      int index = map.get(numbers[i]);
                      result[0] = index+1 ;
                      result[1] = i+1;
                      break;
              } else {
                      map.put(target - numbers[i], i);
              }
       }

      return result;
}

}

Public Instance Methods

solve(collection, target) click to toggle source
# File lib/algorithmable/cups/two_sum.rb, line 50
def solve(collection, target)
end