Judge returns wrong solution but works fine on my local machine


  • 0
    R

    This solution works on my local machine but on the judge this returns a completely wrong solution. Has this happened with anyone ? I am very confused please help.

    class Solution:
        def largestNumber(self, nums):
            for i in range(1, 20):
                noHits = True
                countingSort = [[] for i in range(0, 10)]
                modifiedIdx = set()
                for idx, n in enumerate(nums):
                    strVal = str(n)
                    digitStr = None
                    if i <= len(strVal):
                        digitStr = strVal[-i]
                    if digitStr:
                        digit = int(digitStr)
                        countingSort[digit].append(idx)
                        modifiedIdx.add(idx)
                        noHits = False
                if noHits:
                    break
                ordering = []
                for i in range(9, -1, -1):
                    for j in countingSort[i]:
                        ordering.append(j)
                buffer,c = [],0
                for i in range(0, len(nums)):
                    if i in modifiedIdx:
                        buffer.append(nums[ordering[c]])
                        c += 1
                    else:
                        buffer.append(nums[i])
                nums = copy.deepcopy(buffer)
            result = ""
            for num in nums:
                result += str(num)
            return result
    

  • 0
    R

    @administrators can someone please take a look ?


  • 0
    R

    @1337c0d3r I ran it on another online compiler and the results seem fine but on the leetcode online judge its wrong. Any help will be very welcome.


Log in to reply
 

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