DEV Community

duccanhole
duccanhole

Posted on

5

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
  • 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('');
};
Enter fullscreen mode Exit fullscreen mode

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

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay