diff --git a/168. Excel Sheet Column Title.md b/168. Excel Sheet Column Title.md new file mode 100644 index 0000000..fbd00a7 --- /dev/null +++ b/168. Excel Sheet Column Title.md @@ -0,0 +1,18 @@ +# [168. Excel Sheet Column Title](https://leetcode.com/problems/excel-sheet-column-title/description/) +# 思路 +题目的要求相当于是十进制转二十六进制。用一个循环每次对n取模然后n除26进入下一次循环即可。 +不过需要注意的是,题目给的是1-26对应A-Z而不是0-25对应A-Z,所以每次循环时都要对n作自减操作。 +# C++ +``` +class Solution { +public: + string convertToTitle(int n) { + string res; + while (n > 0) { + res = (char)('A' + (--n) % 26) + res; + n /= 26; + } + return res; + } +}; +```