C# Solution


  • 0
            public string ConvertToTitle(int n)
            {
                int temp = n;
                StringBuilder tempResult = new StringBuilder();
                char[] result = null;
    
                while (temp != 0)
                {
                    temp--;
                    tempResult.Append((char)(temp % 26 + 65));
                    temp /= 26;
                }
    
                result = tempResult.ToString().ToCharArray();
                Array.Reverse(result);
                return new string(result);
            }
    
    The key point is that there is not 0 in number sequence. 'A' maps to '1'. So it is not a simply converting. But you need to minus 1 every time.

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.