Excel Sheet Column Title
Given a positive integer, return its corresponding column title as appear in an Excel sheet.
For example:
1, A 2, B 3, C ... AA, Z
Ideas:
10 binary to 26 binary. The first low and then the high, and 10 into the same as the 2 binary system.
Exercises
classSolution { Public: stringConverttotitle (intN) {stringRes; while(n) {n-=1; Charc = n% -+'A'; Res= c+Res; N/= -; } returnRes; }};
View CodeExcel Sheet Column number
Given a column title as appear in an Excel sheet, and return its corresponding column number.
For example:
1, B, 2 C-3 ... 27 AA, Z
Ideas:
26-in-turn 10-in, as with 2-in-turn 10-binary.
Exercises
classSolution { Public: intTitletonumber (strings) {intres =0; for(intI=0; I<s.size (); i++) { Charc =S[i]; intTMP = C'A'+1; Res= res* -+tmp; } returnRes; }};
View Code
[Leetcode] Excel Sheet column Title & Excel Sheet column number