Skip to content

Commit

Permalink
solved: two_sum via bruteforce, O(n^2) time, O(1) space -@iamserda
Browse files Browse the repository at this point in the history
  • Loading branch information
iamserda committed Feb 25, 2025
1 parent 495819a commit 94768a1
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions neetcodeio/algostructybeginners/Lv1-Arrays/twosum_bruteforce.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Solution:
def twoSum(self, nums: list[int], target: int) -> list[int]:
for i in range(len(nums)):
for j in range(i, len(nums)):
if nums[i] + nums[j] == target and i != j:
return [i, j]
return [-1, -1]


arr = [3, 4, 5, 6]
target = 7
sol = Solution()
assert sol.twoSum(arr, target) == [0, 1]

0 comments on commit 94768a1

Please sign in to comment.