标签:
https://leetcode.com/problems/excel-sheet-column-title/
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
解题思路:
Excel Sheet Column Number 的follow-up,像上一题提到的。26进制实际上是从0-25,而本题的数字是从1-26。所以计算的时候,需要将数字减一。
public class Solution { public String convertToTitle(int n) { String res = ""; while(n > 0) { res = (char)(‘A‘ + (n - 1) % 26) + res; n = (n - 1) / 26; } return res; } }
标签:
原文地址:http://www.cnblogs.com/NickyYe/p/4614696.html