public class Solution {
public int MySqrt(int x) {
long r = x;
while (r * r > x)
r = (r + x / r) / ;
return (int)r;
}
}

https://leetcode.com/problems/sqrtx/#/description

补充一个python的实现:

 class Solution:
def mySqrt(self, x: int) -> int:
r = x
while r * r > x:
r = (r + x // r) //
return int(r)

使用内置函数:

 class Solution:
def mySqrt(self, x: int) -> int:
return int(x ** 0.5)

leetcode69的更多相关文章

  1. leetcode-69.x的平方根

    leetcode-69.x的平方根 Points 二分查找 牛顿迭代 题意 实现 int sqrt(int x) 函数. 计算并返回 x 的平方根,其中 x 是非负整数. 由于返回类型是整数,结果只保 ...

  2. [Swift]LeetCode69. x 的平方根 | Sqrt(x)

    Implement int sqrt(int x). Compute and return the square root of x, where x is guaranteed to be a no ...

  3. leetcode69 X的平方根的几种解法

    第一种自然就是调APi啦(手动滑稽) public int mySqrt(int x) { return (int)Math.sqrt(x); } 时间是52 ms,还超过了1/5的人呢 第二种 二分 ...

  4. 【leetcode-69】 x 的平方根

    (主要是越界问题) 实现 int sqrt(int x) 函数. 计算并返回 x 的平方根,其中 x 是非负整数. 由于返回类型是整数,结果只保留整数的部分,小数部分将被舍去. 示例 1: 输入: 4 ...

  5. LeetCode69.x的平方根

    实现 int sqrt(int x) 函数. 计算并返回 x 的平方根,其中 x 是非负整数. 由于返回类型是整数,结果只保留整数的部分,小数部分将被舍去. 示例 1: 输入: 4 输出: 2 示例 ...

  6. leetcode69. x 的平方根 🌟

    题目: 实现 int sqrt(int x) 函数. 计算并返回 x 的平方根,其中 x 是非负整数. 由于返回类型是整数,结果只保留整数的部分,小数部分将被舍去. 示例 1: 输入: 4 输出: 2 ...

  7. LeetCode69 Sqrt(x)

    题意: Implement int sqrt(int x). Compute and return the square root of x.(Medium) 分析: 二分搜索套路题,不能开方开尽的时 ...

  8. tusen 刷题

    //1.single number和变体 //2.lru lfu 3.给一个正整数集合,求一个和最大且能被3整除的子集.Follow up: 如果集合里有正有负 4.leetcode200-numbe ...

  9. leetcode学习目录

    1  leetcode-69. x 的平方根   https://www.cnblogs.com/shoshana-kong/p/9745424.html 2. 3. 4. 5. 6.

随机推荐

  1. 【Demo】CSS3 动画文字

    效果图: 完整代码: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> &l ...

  2. vue 子组件把数据传递给父组件

    <div id="app"> <child v-on:drop='parent'></child> //这里v-on:drop="pa ...

  3. 一次SQLServer索引损坏问题的排查与修复

    线上库执行一项数据变更操作时,一直提示"出现错误 8646.请记录该错误和时间,并与您的系统管理员联系." 通过代码排查,最终确定是在执行某存储过程时触发了如下错误,并指明了位置是 ...

  4. 联想A390T刷机ROOT教程

    一.联想A390T手动进入Recovery的方法: [步骤一]首先,将你的A390T手机关机,关机状态下,先按住电源键2秒,不要松开,再同时按下音量加.音量减两个键,此时,3个键一直按住不要放开,几秒 ...

  5. 201621123005《Java程序设计》实验总结

    201621123005<Java程序设计>第七次实验总结 1. 本周学习总结 1.1 思维导图:Java图形界面总结 2.书面作业 1. GUI中的事件处理 1.1 写出事件处理模型中最 ...

  6. L181 The microscopic structure of a cat’s tongue helps keep its fur clean

    T.S. eliot's mystery cat, Macavity, besides being a criminal mastermind able to evade the combined r ...

  7. New Concept English Two 19 49

    $课文47 嗜酒的鬼魂 481. A public house which was recently bought by Mr.Ian Thompson is up for sale. 伊恩.汤普森先 ...

  8. POJ 2406Power Strings(KMP)

    POJ 2406 其实就是一个简单的kmp应用: ans = n % (n - f[n]) == 0 ? n / (n - f[n]) : 1 其中f是失配函数 //#pragma comment(l ...

  9. /sys/kernel/debug/usb/devices解析

    1.概述 USB设备通过debugfs导出/sys/kernel/debug/usb/devices显示内核已知的每个USB设备及其配置描述符.此文件对于用户模式下的状态查看工具非常方便,可以扫描文本 ...

  10. BNF 和 ABNF 扩充巴科斯范式 了解

    BNF 巴科斯范式(BNF: Backus-Naur Form 的缩写)是由 John Backus 和 Peter Naur 首先引入的用来描述计算机语言语法的符号集.现在,几乎每一位新编程语言书籍 ...