Given a 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
Solution: 由于A->1, 计算s的末尾时需先减去1
1 class Solution { 2 public: 3 string convertToTitle(int n) { 4 string s; 5 while(n){ 6 s = (char)(‘A‘+(n-1)%26)+s; 7 n = (n-1)/26; 8 } 9 return s; 10 } 11 };
时间: 2024-12-18 03:17:02