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-java11 Show documentation
Show all versions of leetcode-in-java11 Show documentation
Java Solution for LeetCode algorithm problems, continually updating
The newest version!
package g0101_0200.s0171_excel_sheet_column_number;
// #Easy #Top_Interview_Questions #String #Math #2022_06_26_Time_2_ms_(76.43%)_Space_43_MB_(34.53%)
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;
}
}