is this correct translation of 3rd solution in Python?

  • 0

    Re: Two Sum
    I use Python and I think this is the translation of the 3rd solution, but it doesn't work for case [0,4,3,0]
    when I submit it. Can someone help me check what is wrong in the code? (Sorry but I don't understand C or C++, and this problem is my very first leetcode problem...)

    class Solution(object):
        def twoSum(self, nums, target):
            :type nums: List[int]
            :type target: int
            :rtype: List[int]
            for i in range(0, len(nums)):
                complement = target - nums[i]
                if complement in nums:
                    return sorted([i, nums.index(complement)])

Log in to reply

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