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

g0101_0200.s0171_excel_sheet_column_number.Solution.kt Maven / Gradle / Ivy

There is a newer version: 1.30
Show newest version
package g0101_0200.s0171_excel_sheet_column_number

// #Easy #Top_Interview_Questions #String #Math
// #2022_10_12_Time_310_ms_(30.68%)_Space_35_MB_(77.27%)

class Solution {
    fun titleToNumber(s: String): Int {
        var num = 0
        var pow = 0
        for (i in s.length - 1 downTo 0) {
            num += Math.pow(26.0, pow++.toDouble()).toInt() * (s[i].code - 'A'.code + 1)
        }
        return num
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy