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-java Show documentation
Show all versions of leetcode-in-java Show documentation
Java-based LeetCode algorithm problem solutions, regularly updated
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;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy