Why output on leetcode is different from the output on my console?


  • 0
    L

    Why output on leetcode is different from the output on my console?

    Below is my code. The output on my console is: "[[3, 0], [6, 0], [7, 0], [5, 2], [3, 4], [5, 3], [6, 2], [2, 7], [9, 0], [1, 9]]", which is expected solution on leetcode. However, this code's output from leetcode is "[[3,0],[6,0],[7,0],[5,2],[3,4],[6,2],[5,3],[2,7],[9,0],[1,9]]"

    What happened?

    class Solution(object):
        def reconstructQueue(self, people):
            """
            :type people: List[List[int]]
            :rtype: List[List[int]]
            """
            if len(people)==0:
                return []
            SortedPeople=sorted(people,key=lambda arr:arr[0],reverse=1)    
            Result=[SortedPeople[0]]
    
            for p in range(1,len(people)):
                if SortedPeople[p][1]>len(Result)-1:
                    Result.append(SortedPeople[p])
    #                 print(Result)
                else:
                    Result.insert(SortedPeople[p][1],SortedPeople[p])
    #                 print(Result)
            return Result
    
    # print(Solution().reconstructQueue([[7,0], [4,4], [7,1], [5,0], [6,1], [5,2]]))
    print(Solution().reconstructQueue([[3,0],[6,0],[7,0],[5,2],[3,4],[6,2],[5,3],[2,7],[9,0],[1,9]]))
    

Log in to reply
 

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