From 302276b0c0e69a691938f64140de2e748bc29375 Mon Sep 17 00:00:00 2001 From: Yuriy Alexander Date: Tue, 1 Nov 2022 16:12:39 -0700 Subject: [PATCH] brute force --- 01_01/two_sum_stub.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/01_01/two_sum_stub.py b/01_01/two_sum_stub.py index 1f9ea84..41be8a9 100644 --- a/01_01/two_sum_stub.py +++ b/01_01/two_sum_stub.py @@ -1,7 +1,11 @@ # 2-Sum Interview Problem def two_sum_problem(arr, target): - pass + for i in range(len(arr) - 1, target): + for j in range(i + 1, len(arr)): + if arr[i] + arr[j] == target: + return i, j + return None assert two_sum_problem([1, 2, 3], 4) in [(0, 2), (2, 0)]