From 7c84903a324604588a0480ee350a043d9308c628 Mon Sep 17 00:00:00 2001 From: mohaned mashaly <30902228+12mohaned@users.noreply.github.com> Date: Sun, 5 Apr 2020 22:59:25 +0200 Subject: [PATCH] return the index of Two Numbers equals to sum --- algorithms/math/two-sums | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 algorithms/math/two-sums diff --git a/algorithms/math/two-sums b/algorithms/math/two-sums new file mode 100644 index 00000000..f10f569b --- /dev/null +++ b/algorithms/math/two-sums @@ -0,0 +1,20 @@ +""" +Complexity = O(N*M) +Given an Array of Integers +return the index of the two numbers which their sum is equals +to the target + +""" +def twoSum(nums, target): + i = 0 + flag = False + for i in range(len(nums)): + if(flag): + break + for j in range(len(nums)): + if( i !=j ): + if(nums[i] + nums[j] == target): + print(str(i) + " " + str(j)) + flag = True + +