Skip to content

Commit 909186e

Browse files
committed
Runtime: 2571 ms (Top 18.27%) | Memory: 17.10 MB (Top 86.21%)
1 parent 0332026 commit 909186e

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed
+7-12
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
1-
# Runtime: 90 ms (Top 72.15%) | Memory: 15.1 MB (Top 64.41%)
1+
// Runtime: 2571 ms (Top 18.27%) | Memory: 17.10 MB (Top 86.21%)
22

33
class Solution:
4-
54
def twoSum(self, nums: List[int], target: int) -> List[int]:
5+
n = len(nums)
6+
for i in range(n - 1):
7+
for j in range(i + 1, n):
8+
if nums[i] + nums[j] == target:
9+
return [i, j]
10+
return [] # No solution found
611

7-
arr = dict()
8-
# store the index of each number in the array
9-
for i,num in enumerate(nums):
10-
arr[num] = i
11-
12-
# iterate one more time over the array to check if there is any element which complement is in the array
13-
for j, num in enumerate(nums):
14-
rest = target - num
15-
if arr.get(rest, j) != j:
16-
return [j, arr[rest]]

0 commit comments

Comments
 (0)