https://leetcode.com/problems/two-sum/
Algorithm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Input: nums, target
n ← length(nums)
nums ← np.array(nums)
s_nums ← sorted nums
idx ← changed index list
for ix_1 ← 0 to n-1
for ix_2 ← ix_1 to n
e_1 ← s_nums[ix_1]
e_2 ← s_nums[ix_2]
if e_1 + e_2 > target
break
elif e_1 + e_2 = target
return [idx[ix_1], idx[ix_2]]
Code
172ms / 28.4MB
PREVIOUSEtc