New user, please go easy on me. Currently attempting leetcode twosum example and cannot return a statement. Oddly it prints when swapped out to the print keyword. The input example is [3,3] and should return [1,0] or [0,1] when the statement is returned. Looking at other questions on S/O it has to do with the subcall returning to the original loop but i still don't fully understand. Any tips?
class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
self.nums = nums
self.target = target
nums = tuple(nums) #issue happens as a tuple and list.
for x in nums:
for y in nums:
if (x+y) == target:
#print ([x,y])
if (nums.index(x)!=nums.index(y) ):
return([nums.index(x), nums.index(y)]) #this statement will normally print
# are any of the lines below necessary?
else:
continue
return
return, and without that you'll justcontinuethe loop regardless of theelse.