Golang | Leetcode Golang题解之第69题x的平方根

题目:

题解:

Go 复制代码
func mySqrt(x int) int {
    if x == 0 {
        return 0
    }
    C, x0 := float64(x), float64(x)
    for {
        xi := 0.5 * (x0 + C/x0)
        if math.Abs(x0 - xi) < 1e-7 {
            break
        }
        x0 = xi
    }
    return int(x0)
}
相关推荐
念何架构之路6 小时前
go-grpc设计思想
开发语言·后端·golang
microrain7 小时前
SagooIoT 的缓存换后端只改一行配置,文件后端连 Redis 都不需要
物联网·缓存·golang·sagooiot
y1su9 小时前
Leetcode 字符串模板
java·数据结构·算法·leetcode·职场和发展·动态规划
喵了几个咪9 小时前
GoWind ShortPlay 深度拆解:三服务 BFF + Core,一条请求的完整工程链路
golang·gowind
lvwangshu11 小时前
P8981 「DROI」Round 1 距离 题解
动态规划·图论·题解·dp·树形dp·技巧·换根dp·性质题·思维好题
Xin77015 小时前
LeetCode 46. 全排列(回溯法)
leetcode
文丑颜不良啊17 小时前
LeetCode476~500题目解析
java·leetcode
Tsuki_tl18 小时前
【优选算法:双指针】——复写零题解
java·c++·算法·leetcode·数组·双指针·复写零
Cccp.12320 小时前
【leetcode】(十四)从暴力递归到动态规划
数据结构·算法·leetcode·动态规划
旖旎夜光20 小时前
LeetCode 215: 数组中的第K个最大元素 (快速排序) —— 题解
c++·学习·算法·leetcode·力控