Skip to content

Commit 94768a1

Browse files
committed
solved: two_sum via bruteforce, O(n^2) time, O(1) space -@iamserda
1 parent 495819a commit 94768a1

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution:
2+
def twoSum(self, nums: list[int], target: int) -> list[int]:
3+
for i in range(len(nums)):
4+
for j in range(i, len(nums)):
5+
if nums[i] + nums[j] == target and i != j:
6+
return [i, j]
7+
return [-1, -1]
8+
9+
10+
arr = [3, 4, 5, 6]
11+
target = 7
12+
sol = Solution()
13+
assert sol.twoSum(arr, target) == [0, 1]

0 commit comments

Comments
 (0)