zoukankan      html  css  js  c++  java
  • [leedcode 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
    public class Solution {
        public String convertToTitle(int n) {
            //本题是10进制转化为26进制,从结果的低位到高位计算(先取模再求余),注意n需要减一(780)
            //注意最后res字符串,需要头插法
            StringBuilder res=new StringBuilder();
            while(n>0){
                int t=(n-1)%26;
                res.insert(0,(char)('A'+t));
                n=(n-1)/26;
            }
            return res.toString();
           
        }
    }
  • 相关阅读:
    Python 实践
    Keras实践
    NLP S实践
    Spark java 实践
    Seaborn数据探索可视化
    Linux实践
    Redis
    ML算法选型
    Elasticsearch issue
    牛客练习赛37
  • 原文地址:https://www.cnblogs.com/qiaomu/p/4696229.html
Copyright © 2011-2022 走看看