168. Excel表列名称
1 class Solution 2 { 3 public: 4 string convertToTitle(int n) 5 { 6 unordered_map<int,char> hash; 7 for(int i = 1;i <= 26;i ++) hash[i] = 'A' + i - 1; 8 string res; 9 while(n) 10 { 11 if(n % 26 == 0) n--,res = hash[n % 26 + 1] + res; 12 else res = hash[n % 26] + res; 13 n = n / 26; 14 } 15 return res; 16 } 17 };
Mamba never out

浙公网安备 33010602011771号