洞察企业如何通过智慧屏幕App开发提高业务效率与用户体验
576
2022-10-09
168. 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
class Solution { public String convertToTitle(int n) { String result = ""; while(n > 0){ result = (char)((n - 1) % 26 + 'A') + result; n = (n-1) / 26; } return result; }}
class Solution { public String convertToTitle(int n) { String answer = ""; while(n > 0) { int mod = (n - 1) % 26; n = (n - 1) / 26; answer = (char)(mod + 65) + answer; } return answer; }}
/** * @param {number} n * @return {string} */var convertToTitle = function(n) { let result = "" while (n > 0) { let digit = n % 26 n = Math.floor(n / 26) if (digit === 0) { n-- digit = 26 } let char = String.fromCharCode(64 + digit) result = char + result } return result};
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~