首页 > 代码库 > leetcode168
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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。