All Downloads are FREE. Search and download functionalities are using the official Maven repository.

g0101_0200.s0171_excel_sheet_column_number.Solution Maven / Gradle / Ivy

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