From f5ebcaeae252f8ae3be1ba5433ea7d67b7b28ab7 Mon Sep 17 00:00:00 2001 From: Abhishek Tiwari Date: Sat, 6 Jan 2024 01:41:15 +0530 Subject: [PATCH] updated logic for optimised two sum --- src/main/kotlin/math/TwoSum.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/math/TwoSum.kt b/src/main/kotlin/math/TwoSum.kt index 6e0fc97..047bde6 100644 --- a/src/main/kotlin/math/TwoSum.kt +++ b/src/main/kotlin/math/TwoSum.kt @@ -39,19 +39,19 @@ fun twoSum(nums: IntArray, target: Int): IntArray{ * of such pairs. * @param nums Array of integers. * @param target Integer target. - * @return Indices of the two numbers such that they add up to target. + * @return the two numbers such that they add up to target. */ fun twoSumOptimised(nums: IntArray, target: Int): IntArray{ val map: MutableMap = HashMap() - for(num in nums) { + for(num in nums) { val targetDiff = target - num; if(map[targetDiff] == null) map[num] = 1 else return intArrayOf(num, targetDiff) } - return intArrayOf(0,1) + return intArrayOf() }