How good this python solution?

  • 0
        def twoSum(self, nums, target):
            for num in nums:
                difference = target - num
                if difference in nums:
                    index1 = nums.index(num)
                    index2 = len(nums) - 1 - nums[::-1].index(difference)
                    if index1 != index2:
                        return [index1, index2]

Log in to reply

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