problem

Sqrt(x)

code

class Solution {
public:
int mySqrt(int x) {// x/b=b
long long res = x;//
while(res*res > x)
{
res = (res + x/res) / ;//
}
return res;
}
};

重点在于理解怎么计算平方根。

The key point is the average result is calculate by "ans = (ans + x / ans) / 2";

参考

1.leetcode_sqrt(x);

【leetcode】69-Sqrt(x)的更多相关文章

  1. 【LeetCode】69. Sqrt(x) 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 方法一:库函数 方法二:牛顿法 方法三:二分查找 日 ...

  2. 【LeetCode】69. Sqrt(x) (2 solutions)

    Sqrt(x) Implement int sqrt(int x). Compute and return the square root of x. 解法一:牛顿迭代法 求n的平方根,即求f(x)= ...

  3. 【一天一道LeetCode】#69. Sqrt(x)

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Impleme ...

  4. 【LEETCODE】69、动态规划,easy,medium级别,题目:198、139、221

    package y2019.Algorithm.dynamicprogramming.easy; /** * @ProjectName: cutter-point * @Package: y2019. ...

  5. 【LeetCode】代码模板,刷题必会

    目录 二分查找 排序的写法 BFS的写法 DFS的写法 回溯法 树 递归 迭代 前序遍历 中序遍历 后序遍历 构建完全二叉树 并查集 前缀树 图遍历 Dijkstra算法 Floyd-Warshall ...

  6. 【leetcode】963. Minimum Area Rectangle II

    题目如下: Given a set of points in the xy-plane, determine the minimum area of any rectangle formed from ...

  7. 【LeetCode】319. Bulb Switcher 解题报告(Python)

    [LeetCode]319. Bulb Switcher 解题报告(Python) 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/bulb ...

  8. 【LeetCode】722. Remove Comments 解题报告(Python)

    [LeetCode]722. Remove Comments 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode.com/problems/remove-c ...

  9. 【LeetCode】Minimum Depth of Binary Tree 二叉树的最小深度 java

    [LeetCode]Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum dept ...

  10. 【Leetcode】Pascal's Triangle II

    Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1,3 ...

随机推荐

  1. 【Linux】shell学习之sed

    sed替换命令 使用该命令,可以将特定字符串或匹配的规则表达式用另一个字符串替换. sed 's/88/--/' filename 将filename每行第一次出现的88用字符串--替换,然后将该文件 ...

  2. 深入浅出php socket编程

    对TCP/IP.UDP.Socket编程这些词你不会很陌生吧?随着网络技术的发展,这些词充斥着我们的耳朵.那么我想问: 1.什么是TCP/IP.UDP?2.Socket在哪里呢?3.Socket是什么 ...

  3. Linux五种IO模型(同步 阻塞概念)

    Linux五种IO模型 同步和异步 这两个概念与消息的通知机制有关. 同步 所谓同步,就是在发出一个功能调用时,在没有得到结果之前,该调用就不返回.比如,调用readfrom系统调用时,必须等待IO操 ...

  4. forget sus,syn sym semi word out~s

    1★ sus 在~下面     2★ syn 3★ sym 共同   4★ semi   半  

  5. How can I perform the likelihood ratio, Wald, and Lagrange multiplier (score) test in Stata?

      http://www.ats.ucla.edu/stat/stata/faq/nested_tests.htm The likelihood ratio (lr) test, Wald test, ...

  6. JavaScipt 中的事件循环(event loop),以及微任务 和宏任务的概念

    说事件循环(event loop)之前先要搞清楚几个问题. 1. js为什么是单线程的? 试想一下,如果js不是单线程的,同时有两个方法作用dom,一个删除,一个修改,那么这时候浏览器该听谁的?   ...

  7. tomcat vue webpack vue-router 404

    社区已经有结局方案了, http://blog.csdn.net/hayre/article/details/70145513

  8. linux操作系统及命令Part 2

    cat 命令 cat .txt .txt .txt > Ta.txt 将左边三个文件纵向合并为Ta文件 cat .txt>> Ta.txt 将左边文件的内容添加到Ta文件中 tar ...

  9. python3 线程池-threadpool模块与concurrent.futures模块

    多种方法实现 python 线程池 一. 既然多线程可以缩短程序运行时间,那么,是不是线程数量越多越好呢? 显然,并不是,每一个线程的从生成到消亡也是需要时间和资源的,太多的线程会占用过多的系统资源( ...

  10. Java:<获取>、<删除>指定文件夹及里面所有文件

    工具类代码如下: 一.获取 public Class Test{ //定义全局变量,存放所有文件夹下的文档 List<String> fileList ; public List<S ...