"Submission Result: Time Limit Exceeded More Details "? Are you sure?


  • 0
    W
    class Solution(object):
        def two_sum(self, nums, target):
            """
            :type nums: List[int]
            :type target: int
            :rtype: List[int]
            """
            first_num = None
            second_num = None
            nums_level2 = nums
            for num_level1 in nums:
                for num_level2 in nums_level2:
                    if not first_num:
                        first_num = num_level1
                        continue
                    if not second_num:
                        second_num = num_level2
                        continue
                    if second_num == first_num:
                        second_num = num_level2
                        continue
                    result = first_num + second_num
                    if result != target:
                        second_num = num_level2
                        continue
                    if result == target and \
                            nums.index(first_num) < nums.index(second_num):
                        return [nums.index(first_num)+1,
                                nums.index(second_num)+1]
                first_num = num_level1
                nums_level2 = nums[nums.index(first_num)+1:]
            return None

Log in to reply
 

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