Accepted Python3 Solution


  • 0
    W
    class Solution:
        def twoSum(self, nums, target):
            """
            :type nums: List[int]
            :type target: int
            :rtype: List[int]
            """
            ordered_nums = list(enumerate(nums))
            ordered_nums.sort(key=lambda x: x[1])
            while len(ordered_nums) >= 2:
                lhs = ordered_nums[0]
                for rhs in ordered_nums[1:]:
                    if lhs[1] + rhs[1] == target:
                        return [lhs[0], rhs[0]]
                del ordered_nums[0]
            return None
    

Log in to reply
 

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