Compile Error but solution works on my mac


  • 0
    H
    class Solution:
        # @return a string
        a = [chr(one) for one in range(65, 65 + 26)]
    
        def getMin(self, i):
            from math import pow
            result = 0
            for i in range(i-1, -1, -1):
                result += pow(26, i)
    
            return result
    
        def getValue(self, *args):
            from math import pow
            a = 0
            for i in range(len(args) - 1, -1, -1):
                a += pow(26, i) * args[-i - 1]
    
            return a
    
        def convertToTitle(self, num):
            i = 1
    
            while True:
                min1, min2 = self.getMin(i), self.getMin(i+1)
                if min1 < num < min2:
                    break
                elif num == min1:
                    return "".join(["A"] * i)
                elif num == min2:
                    return "".join(["A"] * (i+1))
                i += 1
    
            prefix = [1] * i
    
            for i in range(len(prefix)):
                while True:
                    adjustPrefix = list(prefix)
                    adjustPrefix[i] += 1
                    min1, min2 = self.getValue(*prefix), self.getValue(*adjustPrefix)
                    if min1 < num < min2:
                        break
                    elif num == min1:
                        return "".join([self.a[one-1] for one in prefix])
                    elif num == min2:
                        return "".join([self.a[one-1] for one in adjustPrefix])
                    prefix[i] += 1
    
            return "".join([self.a[one-1] for one in prefix])

  • 0
    H

    I tried python2.6, python2.7, all works. but here compile error.


Log in to reply
 

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