{"id":155,"date":"2017-08-25T22:47:17","date_gmt":"2017-08-25T14:47:17","guid":{"rendered":"https:\/\/www.ccagml.com\/?p=155"},"modified":"2018-11-27T16:48:10","modified_gmt":"2018-11-27T08:48:10","slug":"168-excel-sheet-column-title","status":"publish","type":"post","link":"https:\/\/www.ccagml.com\/?p=155","title":{"rendered":"168. Excel Sheet Column Title"},"content":{"rendered":"<p>Given a positive integer, return its corresponding column title as appear in an Excel sheet.<\/p>\n<p>For example:<\/p>\n<pre>    1 -&gt; A\r\n    2 -&gt; B\r\n    3 -&gt; C\r\n    ...\r\n    26 -&gt; Z\r\n    27 -&gt; AA\r\n    28 -&gt; AB \r\n    ...\r\n<\/pre>\n<p><strong>Example 1:<\/strong><\/p>\n<pre><strong>Input:<\/strong> 1\r\n<strong>Output:<\/strong> \"A\"\r\n<\/pre>\n<p><strong>Example 2:<\/strong><\/p>\n<pre><strong>Input:<\/strong> 28\r\n<strong>Output:<\/strong> \"AB\"\r\n<\/pre>\n<p><strong>Example 3:<\/strong><\/p>\n<pre><strong>Input:<\/strong> 701\r\n<strong>Output:<\/strong> \"ZY\"<\/pre>\n<p><strong>Python<\/strong><\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\"> \r\nclass Solution(object):\r\n    def convertToTitle(self,  n):\r\n        &quot;&quot;&quot;\r\n        :type n: int\r\n        :rtype: str\r\n        &quot;&quot;&quot;\r\n        d = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', \r\n             'T', 'U', 'V', 'W', 'X', 'Y', 'Z']\r\n        result = ''\r\n        temp = 0\r\n        while n:\r\n            temp = n % 26\r\n            n \/= 26\r\n            if temp == 0:\r\n                result += &quot;Z&quot;\r\n                n -= 1\r\n            else:\r\n                result += d[temp-1]\r\n        return result[::-1]\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Given a positive integer, return its corresponding colu<a href=\"https:\/\/www.ccagml.com\/?p=155\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">168. Excel Sheet Column Title<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[29,20],"tags":[],"_links":{"self":[{"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/posts\/155"}],"collection":[{"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=155"}],"version-history":[{"count":1,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/posts\/155\/revisions"}],"predecessor-version":[{"id":156,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/posts\/155\/revisions\/156"}],"wp:attachment":[{"href":"https:\/\/www.ccagml.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=155"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=155"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=155"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}