Skip to content

Commit

Permalink
impl excel sheet column number
Browse files Browse the repository at this point in the history
  • Loading branch information
SKTT1Ryze committed Mar 11, 2024
1 parent 91b6fcd commit 0c40fef
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion leetcode-cc/ExcelSheetColNum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,17 @@ class SExcelSheetColNum : public ISolution {
int benchmark() const override { return 0; }

private:
int titleToNumber(string columnTitle) const {}
int titleToNumber(string columnTitle) const {
int n = columnTitle.size();
int k = 0;
int res = 0;

for (int i = n - 1; i >= 0; i--) {
int num = columnTitle[i] - 'A' + 1;
res += num * pow(26, k);
k++;
}

return res;
}
};

0 comments on commit 0c40fef

Please sign in to comment.