{"id":8880,"date":"2021-11-28T14:24:48","date_gmt":"2021-11-28T22:24:48","guid":{"rendered":"https:\/\/zxi.mytechroad.com\/blog\/?p=8880"},"modified":"2021-11-28T14:36:10","modified_gmt":"2021-11-28T22:36:10","slug":"leetcode-168-excel-sheet-column-title","status":"publish","type":"post","link":"https:\/\/zxi.mytechroad.com\/blog\/math\/leetcode-168-excel-sheet-column-title\/","title":{"rendered":"\u82b1\u82b1\u9171 LeetCode 168. Excel Sheet Column Title"},"content":{"rendered":"\n<p>Given an integer&nbsp;<code>columnNumber<\/code>, return&nbsp;<em>its corresponding column title as it appears in an Excel sheet<\/em>.<\/p>\n\n\n\n<p>For example:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted;crayon:false\">A -> 1\nB -> 2\nC -> 3\n...\nZ -> 26\nAA -> 27\nAB -> 28 \n...\n<\/pre>\n\n\n\n<p><strong>Example 1:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted;crayon:false\"><strong>Input:<\/strong> columnNumber = 1\n<strong>Output:<\/strong> \"A\"\n<\/pre>\n\n\n\n<p><strong>Example 2:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted;crayon:false\"><strong>Input:<\/strong> columnNumber = 28\n<strong>Output:<\/strong> \"AB\"\n<\/pre>\n\n\n\n<p><strong>Example 3:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted;crayon:false\"><strong>Input:<\/strong> columnNumber = 701\n<strong>Output:<\/strong> \"ZY\"\n<\/pre>\n\n\n\n<p><strong>Example 4:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted;crayon:false\"><strong>Input:<\/strong> columnNumber = 2147483647\n<strong>Output:<\/strong> \"FXSHRXW\"\n<\/pre>\n\n\n\n<p><strong>Constraints:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><code>1 &lt;= columnNumber &lt;= 2<sup>31<\/sup>&nbsp;- 1<\/code><\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Solution: Base conversion<\/strong><\/h2>\n\n\n\n<p>Time complexity: O(logn)<br>Space complexity: O(logn)<\/p>\n\n\n\n<div class=\"responsive-tabs\">\n<h2 class=\"tabtitle\">C++<\/h2>\n<div class=\"tabcontent\">\n\n<pre lang=\"c++\">\/\/ Author: Huahua\nclass Solution {\npublic:\n  string convertToTitle(int n) {\n    string ans;\n    do {\n      n--;\n      ans += 'A' + (char)(n % 26);\n      n \/= 26;\n    } while (n);\n    reverse(begin(ans), end(ans));\n    return ans;\n  }\n};\n<\/pre>\n<\/div><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Related Problems<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/zxi.mytechroad.com\/blog\/math\/leetcode-171-excel-sheet-column-number\/\" data-type=\"post\" data-id=\"8884\">\u82b1\u82b1\u9171 LeetCode 171. Excel Sheet Column Number<\/a><\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Given an integer&nbsp;columnNumber, return&nbsp;its corresponding column title as it appears in an Excel sheet. For example: A -> 1 B -> 2 C -> 3&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[49],"tags":[379,222,31],"class_list":["post-8880","post","type-post","status-publish","format-standard","hentry","category-math","tag-base","tag-easy","tag-math","entry","simple"],"_links":{"self":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/8880","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/comments?post=8880"}],"version-history":[{"count":3,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/8880\/revisions"}],"predecessor-version":[{"id":8887,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/8880\/revisions\/8887"}],"wp:attachment":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/media?parent=8880"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/categories?post=8880"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/tags?post=8880"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}