python o(n) to slove the problem


  • -1
    H
    class Solution:
        def twoSum(self, nums, target):
            """
            :type nums: List[int]
            :type target: int
            :rtype: List[int]
            """
            for x in range(len(nums)):   
                    aa = target - nums[x]
                    # print(aa)
                    if aa in nums:
                        b = nums.index(aa)
                        if x == b:
                            continue
                        return[x,b]     
    

  • 0

    That's not o(n). Not even O(n).


Log in to reply
 

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