code every day with me

–DAY 22–

Hi, I am going to make #100DaysOfCode Challenge. Everyday I will try solve 1 problem from leetcode or hackerrank. Hope you can go with me until end.
Now let’s solve problem today:

Problem: Excel Sheet Column Title
Detail: here


This content originally appeared on DEV Community and was authored by duccanhole

--DAY 22--

Hi, I am going to make #100DaysOfCode Challenge. Everyday I will try solve 1 problem from leetcode or hackerrank. Hope you can go with me until end.
Now let's solve problem today:

  • Problem: Excel Sheet Column Title
  • Detail: here
  • Idea: it's pretty similar to convert number to binary
  • My solution(javascript):
var convertToTitle = function(n) {
    let column = 'ZABCDEFGHIJKLMNOPQRSTUVWXYZ';
    let result = '';
    while(n>26){
        let tmp = n%26;
        result += column.charAt(tmp);
        if(n%26==0) n = Math.floor(n/27);
        else n = Math.floor(n/26);
    }
    result += column.charAt(n);
    return result.split('').reverse().join('');
};

-->If you have better solution or any question, please comment below. I will appreciate.


This content originally appeared on DEV Community and was authored by duccanhole


Print Share Comment Cite Upload Translate Updates
APA

duccanhole | Sciencx (2021-11-17T02:30:36+00:00) code every day with me. Retrieved from https://www.scien.cx/2021/11/17/code-every-day-with-me-9/

MLA
" » code every day with me." duccanhole | Sciencx - Wednesday November 17, 2021, https://www.scien.cx/2021/11/17/code-every-day-with-me-9/
HARVARD
duccanhole | Sciencx Wednesday November 17, 2021 » code every day with me., viewed ,<https://www.scien.cx/2021/11/17/code-every-day-with-me-9/>
VANCOUVER
duccanhole | Sciencx - » code every day with me. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/11/17/code-every-day-with-me-9/
CHICAGO
" » code every day with me." duccanhole | Sciencx - Accessed . https://www.scien.cx/2021/11/17/code-every-day-with-me-9/
IEEE
" » code every day with me." duccanhole | Sciencx [Online]. Available: https://www.scien.cx/2021/11/17/code-every-day-with-me-9/. [Accessed: ]
rf:citation
» code every day with me | duccanhole | Sciencx | https://www.scien.cx/2021/11/17/code-every-day-with-me-9/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.