8 lines python solution


  • 0
    K
    n=len(nums)
    for i in range(0,n):
        m=target-nums[i]
        if m in nums:
            q=nums.index(m)
            if i!=q:
                break
    return [i,q]

  • 0
    L

    @kong75 this does not rule out the case where nums[i] appears more than once in nums


  • 0
    K

    @lil It is assumed that each input would have exactly one solution. Thus, I think there should be only one output and we can ignore the case that nums[i] appears more than once :)


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.