g0101_0200.s0171_excel_sheet_column_number.Solution Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of leetcode-in-java17 Show documentation
Show all versions of leetcode-in-java17 Show documentation
Java Solution for LeetCode algorithm problems, continually updating
package g0101_0200.s0171_excel_sheet_column_number;
// #Easy #Top_Interview_Questions #String #Math
public class Solution {
public int titleToNumber(String s) {
int num = 0;
int pow = 0;
for (int i = s.length() - 1; i >= 0; i--) {
num += (int) Math.pow(26, pow++) * (s.charAt(i) - 'A' + 1);
}
return num;
}
}