leetcode168

Posted AsenYang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了leetcode168相关的知识,希望对你有一定的参考价值。

public class Solution {
    private string Convert(int k)
        {
            var s = "";
            switch (k)
            {
                case 1:
                    s = "A";
                    break;
                case 2:
                    s = "B";
                    break;
                case 3:
                    s = "C";
                    break;
                case 4:
                    s = "D";
                    break;
                case 5:
                    s = "E";
                    break;
                case 6:
                    s = "F";
                    break;
                case 7:
                    s = "G";
                    break;
                case 8:
                    s = "H";
                    break;
                case 9:
                    s = "I";
                    break;
                case 10:
                    s = "J";
                    break;
                case 11:
                    s = "K";
                    break;
                case 12:
                    s = "L";
                    break;
                case 13:
                    s = "M";
                    break;
                case 14:
                    s = "N";
                    break;
                case 15:
                    s = "O";
                    break;
                case 16:
                    s = "P";
                    break;
                case 17:
                    s = "Q";
                    break;
                case 18:
                    s = "R";
                    break;
                case 19:
                    s = "S";
                    break;
                case 20:
                    s = "T";
                    break;
                case 21:
                    s = "U";
                    break;
                case 22:
                    s = "V";
                    break;
                case 23:
                    s = "W";
                    break;
                case 24:
                    s = "X";
                    break;
                case 25:
                    s = "Y";
                    break;
                case 0:
                    s = "Z";
                    break;
            }
            return s;
        }

        public string ConvertToTitle(int n)
        {
            var list = new List<int>();
            while (n != 0)
            {
                var k = n % 26;
                list.Add(k);
                if (k == 0)
                {
                    n = n / 26 - 1;
                }
                else
                {
                    n = n / 26;
                }
            }

            list.Reverse();

            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < list.Count; i++)
            {
                var s = Convert(list[i]);
                sb.Append(s);
            }
            return sb.ToString();
        }
}

https://leetcode.com/problems/excel-sheet-column-title/#/description

以上是关于leetcode168的主要内容,如果未能解决你的问题,请参考以下文章

LeetCode 168 Excel表列名称[26进制] HERODING的LeetCode之路

leetcode算法168.Excel表列名称

精心收集的 48 个 JavaScript 代码片段,仅需 30 秒就可理解

Leetcode.1024 视频拼接

LeetCode810. 黑板异或游戏/455. 分发饼干/剑指Offer 53 - I. 在排序数组中查找数字 I/53 - II. 0~n-1中缺失的数字/54. 二叉搜索树的第k大节点(代码片段

LEETCODE 003 找出一个字符串中最长的无重复片段