From c97f4f45915d5a26f6f8ebc7b77d0a344dc43edc Mon Sep 17 00:00:00 2001 From: SunnyQjm Date: Sun, 28 Jun 2020 22:51:04 +0800 Subject: [PATCH] update --- chapter1/sqrt.py | 4 ++-- chapter3/1_leetcode7.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/chapter1/sqrt.py b/chapter1/sqrt.py index 15bf91e..d80a6cd 100644 --- a/chapter1/sqrt.py +++ b/chapter1/sqrt.py @@ -2,12 +2,12 @@ # coding=utf-8 -################################################################3 +################################################################ # LeetCode: 69 Sqrt(x) # Implement int sqrt(int x). # Compute and return the square root of x, where x is guaranteedto be a non-negative integer. # Since the return type is an integer, the decimal digits aretruncated and only the integer part of the result is returned. -################################################################3 +################################################################ class Solution: def mySqrt(self, x): diff --git a/chapter3/1_leetcode7.py b/chapter3/1_leetcode7.py index a0ab2e0..9e2c377 100644 --- a/chapter3/1_leetcode7.py +++ b/chapter3/1_leetcode7.py @@ -36,12 +36,12 @@ class Solution: 3. 将|x|从个位开始向左遍历,依次叠加到结果里面; 4. 最后判断结果是否溢出(与32位有符号整形的最大值和最小值进行比对) """ - isNegitive = -1 if x < 0 else 1 + isNegative = -1 if x < 0 else 1 result, x = 0, abs(x) while x > 0: result = result * 10 + x % 10 x = x // 10 - result = isNegitive * result + result = isNegative * result return 0 if result > INT_MAX_VAL or result < INT_MIN_VAL else result