• 0

    This is the first time I code on LeetCode. The solution is accepted,but I think the method is not that good.

    class Solution(object):
        def twoSum(self, nums, target):
            :type nums: List[int]
            :type target: int
            :rtype: List[int]
            for i in range(len(nums)):
                tempVal = target - nums[i]
                for j in range(i+1,len(nums)):
                    if tempVal == nums[j]:
                        x = i
                        y = j
                        return x,y

    thx. :)

  • 0

    @LeonWen Try to add if tempVal in nums: before for j in range(i+1,len(nums)):

Log in to reply

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