leetcode 7 Reverse Integer golang实现

xiaoxiao2021-02-28  70

转化为字符换 翻转在转化为int

func reverse(x int) int { max := int(math.Pow(2,31) - 1) _x := int(math.Abs(float64(x))) s := strconv.Itoa(_x) s = res(s) res,_:=strconv.Atoi(s) if res > max { return 0 } if x > 0 { return res } return -res } func res(s string) string { len := len(s) res := "" for i := len - 1; i >= 0 ; i-- { res += string(s[i]) } return res }
转载请注明原文地址: https://www.6miu.com/read-62126.html

最新回复(0)