Skip to content

Commit ffa37c9

Browse files
Update excel_sheet_column_number.cpp
1 parent 6fac47c commit ffa37c9

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

excel_sheet_column_number.cpp

+7-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@ class Solution {
22
public:
33
int titleToNumber(string s) {
44
int result = 0;
5-
for(auto c : s)
6-
result = result * 26 + (c - 'A' + 1);
5+
6+
for(auto c : s) {
7+
int decimal = c - 'A' + 1; //convert 0 based indexing to 1 based indexing hence added once
8+
result = result * 26 + decimal;
9+
}
10+
711
return result;
812
}
9-
};
13+
};

0 commit comments

Comments
 (0)