zoukankan      html  css  js  c++  java
  • [LeetCode]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 

    思路:

    Excel序是这样的:A~Z, AA~ZZ, AAA~ZZZ, ……
    十进制数转26进制数
    注意是从1开始的
    将int值强制转化为char类型

     1 public class Solution168 {
     2     public String convertToTitle(int n) {
     3         String res = "";
     4         while(n>0){
     5             res = (char)((n-1)%26+'A')+res;
     6             n=(n-1)/26;
     7         }
     8         return res;
     9     }
    10     public static void main(String[] args) {
    11         // TODO Auto-generated method stub
    12         Solution168 solution168 = new Solution168();
    13         int n = 27;
    14         System.out.println(solution168.convertToTitle(n));
    15     }
    16 
    17 }
  • 相关阅读:
    文件上传.py
    文件下载.py
    Visual SVN IIS反向代理设置
    开发者工具
    Linux
    装饰器
    面向对象
    django异常--数据库同步
    浅谈 Mysql
    python网络编程系列
  • 原文地址:https://www.cnblogs.com/zlz099/p/8194263.html
Copyright © 2011-2022 走看看