class Solution { public: int titleToNumber(string columnTitle) { int sum=0; int n=columnTitle.size(); for(int i=0;i<n-1;i++) { sum=sum+pow(26,(n-i-1))*(columnTitle[i]-'A'+1); } sum=sum+(columnTitle[n-1]-'A'+1); return sum; } };
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter