From 73a9f5a40b5cc82c5fc44d1471b715c6c9d1d18a Mon Sep 17 00:00:00 2001 From: Jimmy Le Date: Tue, 15 Nov 2016 18:44:32 -0500 Subject: [PATCH] Updated twoSum.java With testing on leetCode, the function twoSum returned indices that were added by 1 integer. Ex. if the actual result was [1, 2], the method returned [2, 3]. Deleted the i+1 in the if & else statements. This works. --- TwoSum.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/TwoSum.java b/TwoSum.java index 81009de..a8114a7 100644 --- a/TwoSum.java +++ b/TwoSum.java @@ -27,9 +27,9 @@ public int[] twoSum(int[] numbers, int target) { for (int i = 0; i < numbers.length; ++i) { int b = target - numbers[i]; if (map.get(b) != null) { - return new int[]{map.get(b),i+1}; - } else map.put(numbers[i],i+1); + return new int[]{map.get(b),i}; + } else map.put(numbers[i],i); } return null; } -} \ No newline at end of file +}