HTMLify

LeetCode - Maximum Value of a String in an Array - Go
Views: 28 | Author: abh
func tpow(x int) int {
    p := 1
    for ;x>1; x-- {
        p *= 10
    }
    return p
}
func maximumValue(strs []string) int {
    var m int
    for _, str := range strs {
         var v int = 0
         for i:=len(str)-1; i>=0; i-- {
            c := str[i]
            if 48 <= c && c <= 57 {
                v += (int(c)-48)*tpow((len(str)-i))
            } else {
                v = len(str)
                break
            }
         }
         if v > m {
            m = v
         }
    }
    return m
}

Comments