.min () arg - пустая последовательность - PullRequest
0 голосов
/ 04 мая 2020

Я пытаюсь решить проблему threesumcloset в leetcode, но я получаю сообщение об ошибке во время выполнения, говорящее «.min () arg - пустая последовательность». Это странно, потому что код отлично работает в моем текстовом редакторе. Кто-нибудь может мне помочь, пожалуйста?

def threeSumClosest(self, nums: List[int], target: int) -> int:
        """
        :type nums: List[int]
        :type target: int
        :rtype: int
        """

        #take in the list
        input = [-1, 2, 1, -4]
        target = 1
        sum = 0

        #creates the list to compare to target
        sum_list = []
        abs_list = []


        #1st for loop 
        for first in nums:

            #2nd loop excluding 1st
            for second in nums:
                if nums.index(first) == nums.index(second):
                    #find a way to skip that number
                    continue
                else:
                    pass
                #3rd loop excluding 1st and 2nd and adds to list 
                for third in nums:
                    if nums.index(first) == nums.index(third) or nums.index(second) == nums.index(third):
                    #find a way to skip that number
                        continue
                    else:
                        pass
                    sum = first + second + third
                    sum_list.append(sum)

        #cast to set and print sum_list
        sum_list = set(sum_list)
        print(sum_list)
        #create a list with the abs of the diff btw the target and sum_list
        abs_list = list(map(lambda x: abs(x - target), sum_list) )
        final_index = abs_list.index(min(abs_list))
        sum_list = list(sum_list)
        return (sum_list[final_index])
...