From ef3b6b170b4759d73845ac0c8391bd9283343b78 Mon Sep 17 00:00:00 2001 From: sangge-rockpi <2251250136@qq.com> Date: Wed, 24 Jan 2024 18:25:02 +0800 Subject: [PATCH] update 69 --- leetcode/69.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/leetcode/69.py b/leetcode/69.py index a5739a1..0b8a481 100644 --- a/leetcode/69.py +++ b/leetcode/69.py @@ -7,6 +7,12 @@ class Solution: # Use Newton's method, return the smaller root # fx = x ** 2 - c # Xn-1 = 0.5 * (Xn + c / Xn) + if c == 0: + return 0 + + if c == 1: + return 1 + x = c / 2 while True: next_x = (x + c / x) / 2