Skip to content

Instantly share code, notes, and snippets.

@cfc1020
Created June 5, 2020 17:18
Show Gist options
  • Save cfc1020/8954a0f30654fd5a075a55146289467a to your computer and use it in GitHub Desktop.
Save cfc1020/8954a0f30654fd5a075a55146289467a to your computer and use it in GitHub Desktop.
excel-sheet-column-title
# @param {Integer} n
# @return {String}
def convert_to_title(n)
res = ''
begin
rem = n % 26
n /= 26
rem = if rem.zero?
n -= 1
25
else
rem - 1
end
res << [*('A'..'Z')].to_a[rem]
end while n.nonzero?
res.reverse
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment