标签:
Given a non-zero positive integer, return its corresponding column title as appear in an Excel sheet.
For example:
1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -> AB
类似于数制转换,只不过1对应A,而不是0对应A
1 class Solution { 2 public: 3 string convertToTitle(int n) { 4 5 string res=""; 6 7 while(n>0) 8 { 9 int tmp=(n-1)%26; 10 res.push_back(‘A‘+tmp); 11 12 n=(n-1)/26; 13 } 14 15 string result(res.rbegin(),res.rend()); 16 return result; 17 } 18 };
【leetcode】Excel Sheet Column Title
标签:
原文地址:http://www.cnblogs.com/reachteam/p/4175758.html