why leetcode is producing different result than pycharm and jupyter notebook

42 Views Asked by At

I copied pasted and used the same input for the method, I get the correct result on my machine but leetcode is producing different result for the same code. this is the code on leetcode for permutuation sequence

class Solution(object):
    def getPermutation(self, n, k):
        list_ = []
        my_num = ''
        for i in range(n):
            list_.append(str(i + 1))
        fact = 1
        n_f = n
        k_f = k
        for i in range(n_f):
            fact *= (i+1)
        diveded = int(fact/n_f)
        if n_f == n:
            no = (k/diveded)
            if int(no) == no:
                no -= 1
                no = int(no)
            else:
                no = int(no)
            my_num += list_[no]
            list_.remove(list_[no])
            n_f -= 1
        while len(my_num) < n:
            fact = 1
            for i in range(n_f):
                fact *= (i + 1)
            no_ = int((k_f-1)%diveded)
            no = int(no_/fact)
            if int(no) == no and no_ > 0:
                no -= 1
                no = int(no)
            else:
                no = int(no)
            used = 0
            for i in range(len(my_num)):
                if int(my_num[i]) < int(list_[no]) and no > 0:


                    used += 1
            no -= used

            diveded = int(fact / n_f)

            while list_[no] in my_num:
                no += 1
            else:
                my_num += list_[no]
                list_.remove(list_[no])
                n_f -= 1
        else:
            return my_num




solu = Solution()
print(solu.getPermutation(3,3))

enter image description here

enter image description here

1

There are 1 best solutions below

0
rochard4u On

This is because you chose Python instead of Python3 as the language on leetcode. You are currently running your code on version 2.7.18 which behave differently than the more recent version.