Skip to content

Commit

Permalink
impl excel sheet column title
Browse files Browse the repository at this point in the history
  • Loading branch information
SKTT1Ryze committed Mar 11, 2024
1 parent 82a2010 commit 285d33f
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions leetcode-cc/ExcelSheetColTitle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ IMPLEMENT_PROBLEM_CLASS(
"Excel Sheet Column Title",
"Given an integer columnNumber, return its corresponding column title as "
"it appears in an Excel sheet.",
{""});
{"Math"});

class SExcelSheetColTitle : public ISolution {
public:
Expand All @@ -26,5 +26,16 @@ class SExcelSheetColTitle : public ISolution {
int benchmark() const override { return 0; }

private:
string convertToTitle(int columnNumber) const {}
string convertToTitle(int columnNumber) const {
string res = "";

while (columnNumber) {
columnNumber--;
int mod = columnNumber % 26;
res = char('A' + mod) + res;
columnNumber /= 26;
}

return res;
}
};

0 comments on commit 285d33f

Please sign in to comment.