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. windows使用git记录

    1.免密码clone远程服务器代码开启ssh 生成私钥公钥 命令:查看自己配置的邮箱 git config user.name git config user.email 生成密钥:邮箱填写上面查看出 ...

  2. 001——php字符串中的字符串定义

    <?php /** * 一.定义字符串: * ''单引号 ""双引号 <<<定界符 */ /* $url='http://baidu.com'; $baid ...

  3. jQuery实现鼠标划过展示大图的方法

    这篇文章主要介绍了jQuery实现鼠标划过展示大图的方法,实例分析了jQuery操作鼠标事件及图片处理的技巧,具有一定参考借鉴价值,需要的朋友可以参考下 本文实例讲述了jQuery实现鼠标划过展示大图 ...

  4. java- Collection Map集合

    package map; import java.util.Collection; import java.util.HashMap; import java.util.Map; import jav ...

  5. linux查看端口对应的程序及pid

    linux中查看特定端口对应的进程以及进程的pid可以使用下面指令: lsof -i:port_number 杀死进程的指令是: kill -s 9 pid

  6. 程序级的AOP到底好不好?

    很多年前模拟过Spring的AOP机制,简单的实现其实不难,但真正要保证切入代码符合预期的设计,不会引起负面影响,特别是要保证原来逻辑的稳定性,即AOP的强壮性.个人感觉还是很难,如果横切的代码过多, ...

  7. c++ 读取所有图片

    copyright by Jun Yang, SUN YAT-SEN UNIVERSITY //FileList.h ///////////////////////////////////////// ...

  8. centOS上安装MySQL5.7

    在centos上安装mysql,前提得有sudo的权限.没有的话先去跟管理员申请一个. STEP 1 - 安装MySQL 首先打开浏览器访问下 https://dev.mysql.com/downlo ...

  9. javascript reg 不加入分组

    from :https://stackoverflow.com/questions/3512471/what-is-a-non-capturing-group-what-does-a-question ...

  10. 【idea】如何破解idea

    1.IntelliJ IDEA官网下载 https://www.jetbrains.com/idea/download/ 2.安装IntelliJ IDEA 3.永久破解 在http://idea.l ...