Monday, August 24, 2015

Leetcode 168. Excel Sheet Column Title

https://leetcode.com/problems/excel-sheet-column-title/

Solution:
# T:O(lgn) S:O(1)
class Solution:
    # @param {integer} n
    # @return {string}
    def convertToTitle(self, n):
        result, dvd = "", n
        
        while dvd:
            result += chr((dvd - 1) % 26 + ord('A'))
            dvd = (dvd - 1) / 26
        
        return result[::-1]
Run Time: 36 ms

No comments:

Post a Comment