[分析]
十进制转26进制,需要注意的是26进制是以1为最小数的。
思路1写了好久,放在这儿用于警示自己还需要更多练习。
public class Solution {
// Method 2
// https://leetcode.com/discuss/19047/my-1-lines-code-in-java-c-and-python
// https://leetcode.com/discuss/34526/share-my-java-solusion
// Using the mod operator gives numbers in range [0, 25].
// That's why he used (n-1) so he's converting n from 1 based to 0 based.
public String convertToTitle(int n) {
String res = "";
while (n > 0) {
res = (char)('A' + (n - 1) % 26) + res;
n = (n - 1) / 26;
}
return res;
}
private static char[] map = new char[27];
static {
for (int i = 1;i <= 26; i++) {
map[i] = (char)('A' + i - 1);
}
}
// Method 1
public String convertToTitle1(int n) {
StringBuilder res = new StringBuilder();
while (n > 0) {
int mod = n % 26;
if (mod == 0) {
res.append('Z');
n -= 26;
} else {
res.append(map[mod]);
}
n /= 26;
}
return res.reverse().toString();
}
}
分享到:
相关推荐
LeetCode-Excel-Sheet-Column-Title
LeetCode-CheatSheet 包含各种用于笔记的文本文件,但主要由这个支持 Markdown 格式语言的 README 文件组成。 这使注释和代码看起来好多了,并支持许多很棒的功能,如快速链接,并使格式化更容易。 先决条件 将来我...
《leetcode-solutions》,刷算法题,需要有一定的英文阅读能力。。。
IDEA 插件,lettcode刷题,leetcode-editor7.4版本下载进行本地导入(直接将压缩包拖进IDEA即可)
Algorithm-LeetCode-Sol-Res.zip,干净,易懂的解决方案和资源,为leetcode在线判断算法问题。,算法是为计算机程序高效、彻底地完成任务而创建的一组详细的准则。
leetcode 171 excel sheet column number python代码 leetcode 171 excel sheet column number python代码
Algorithm-leetcode-spider.zip,leetcode公司,算法是为计算机程序高效、彻底地完成任务而创建的一组详细的准则。
leetcode-cli-plugins leetcode-cli 的第 3 方插件。 什么是 如何使用 如何使用 插件 名称 描述 增强的命令 按公司或标签过滤问题 list 不要在同一台计算机上使 Chrome 的会话过期 login 不要在同一台计算机上使 ...
在IDE中解决LeetCode问题,支持leetcode.com与leetcode-cn.com,满足基本的做题需求。 理论上支持: IntelliJ IDEA PhpStorm WebStorm PyCharm RubyMine AppCode CLion GoLand DataGrip Rider MPS Android Studio。
leetcode-cheat 的发布 它是什么 ? 这是一个chrome 扩展,可以帮助您更高效地使用 leetcode。您可以从 重要: leetcode-cheat 现在只支持中文版。 也就是说不完全支持leetcode.com,但是你可以用leetcode-cn.com代替...
解题思路思路和LeetCode-python 503.下一个更大元素 II一致,只是这里求的是下标的距离,而不是数值倒序搜索,用到栈,栈里存储索引情况1:若栈为
leetcode 刷题全刷备忘单 动机 这是为了帮助我在刷 leetcode 时重新认识一些语法和概念。 C++ 句法技巧 STL & 数组相关 List< int []> p1 = new ArrayList< int []>(); p1.add( new int []{a,b,c}); vector...
leetcode 答案解析 golang解答
~/.vscode/extensions/leetcode.vscode-leetcode-0.17.0/node_modules/vsc-leetcode-cli/bin/leetcode /usr/local/bin/leetcode 修改模板 open ~/.vscode/extensions/leetcode.vscode-leetcode-0.17.0/node_modules/...
leetcode-editor,在ide中做leetcode练习,支持leetcode.com和leetcode-cn.com,以满足练习的基本需求。理论上支持:intellij idea phpstorm webstorm pycharm rubymine appcode clion goland datagrip rider mps ...
leetcode-helper-1.7.1
leetcode-tag-dynamic programming
970. 强整数对数运算function powerfulIntegers(x: number, y: number, bound: number): numb
然后进入到LeetCode-Spider目录中修改config.json,其中outputDir需要填写该工程的/docs/views文件夹路径 { "username": "aaa", "password": "bbb", "outputDir": "/Users/liuyao/Downloads/LeetCode-Blog-Test/docs...