Here is the question in case:
Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.
You may assume that each input would have exactly one solution, and you may not use the same element twice.
You can return the answer in any order.
My Question:
I came up with two different solutions (one using for loop, and the other using while loop) to this question but I believe that they are doing the same operation. They are both brute forcing all possible combinations while avoiding duplicate combinations. However, the first solution will give me a "time limit exceeded" error with large arrays as where the second works fine. I'm not sure what the difference is, they should both be O(n^2)??
num1 = 0
while num1 < len(nums):
num2 = num1+1
while num2 < len(nums):
sum = nums[num1] + nums[num2]
if sum == target:
return [num1, num2]
else:
num2 += 1
num1 += 1
for num1 in range(len(nums)):
for num2 in range(len(nums)):
if num2 > num1:
if nums[num1] + nums[num2] == target:
return [num1, num2]
