日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

LeetCode 168. Excel Sheet Column Title

發(fā)布時(shí)間:2024/4/17 50 豆豆
生活随笔 收集整理的這篇文章主要介紹了 LeetCode 168. Excel Sheet Column Title 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
LeetCode 168. Excel Sheet Column Title

分析

難度 易

來源

https://leetcode.com/problems/excel-sheet-column-title/

十進(jìn)制轉(zhuǎn)26進(jìn)制
注意,z表示26,而非0

題目

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 ????...

Example 1:

Input: 1 Output: "A"

Example 2:

Input: 28 Output: "AB"

Example 3:

Input: 701 Output: "ZY"

解答

1 package LeetCode; 2 3 public class L168_ExcelSheetColumnTitle { 4 public String convertToTitle(int n) { 5 StringBuilder sb=new StringBuilder(); 6 while(n>0){ 7 if(n%26!=0){ 8 sb.append((char)(n%26+64)); 9 n/=26; 10 } 11 else{ 12 sb.append('Z'); 13 n=n/26-1; 14 } 15 } 16 return sb.reverse().toString(); 17 } 18 public static void main(String[] args){ 19 L168_ExcelSheetColumnTitle l168=new L168_ExcelSheetColumnTitle(); 20 System.out.println(l168.convertToTitle(52)); 21 } 22 }

?

?

posted on 2018-11-12 17:32 flowingfog 閱讀(...) 評(píng)論(...) 編輯 收藏

轉(zhuǎn)載于:https://www.cnblogs.com/flowingfog/p/9947861.html

總結(jié)

以上是生活随笔為你收集整理的LeetCode 168. Excel Sheet Column Title的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。