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. 这样好用的ReactiveCocoa,根本停不下来

    作者:空之境界(博客) 前戏我个人非常推崇ReactiveCocoa,它就像中国的太极,太极生两仪,两仪生四象,四象生八卦,八卦生万物.ReactiveCocoa是一个高度抽象的编程框架,它真的很抽象 ...

  2. PL/SQL Developer安装教程

    1.下载:http://pan.baidu.com/s/1qYtvy1I密码:451g instantclient官方下载链接:http://www.oracle.com/technetwork/to ...

  3. SpringMVC中JSP页面显示为源码

    @RequestMapping(value = "login") public ModelAndView login(ModelAndView mav) throws Except ...

  4. jq 如何获取多选框选中的值

    jquery如何获取多选框选中的值,有两种方法 1.通过id获取是否选中(单个) 1)引入jquery文件 2)Html设计如下 <div> <span>运动类:</sp ...

  5. radio选择

    input标签radio单选 <tr> <th style="font-weight: bolder;text-align: right;width:18%" & ...

  6. Java Web(十一) 文件上传与下载

    文件上传 上传的准备工作 表单method必须为post 提供file组件 设置form标签的enctype属性为multipart/form-data,如果没有设置enctype属性,浏览器是无法将 ...

  7. Win10系列:VC++文件选取

    在C++/CX的Windows::Storage::Pickers命名空间中定义了一个FileOpenPicker类,使用此类可以新建一个文件打开选取器,并可以通过这个类里面包含的属性和函数选取一个或 ...

  8. C#通过shell32获取文件详细备注信息

    1.从系统Window/System32文件夹中Copy出 Shell32.dll Com组件 将Shell32.dll文件引用到项目中,并设置“嵌入互操作类型”为false http://blog. ...

  9. Java日期时间,以及相互转换

    Java日期时间,以及相互转化 package com.study.string; import java.text.ParseException; import java.text.SimpleDa ...

  10. [Codeforces513E2]Subarray Cuts

    Problem 给定一个长度为n的数字串,从中选取k个不重叠的子串(可以少选),将每个串求和si 求max|s1 - s2| + |s2 - s3| + ... + |sk - 1 - sk|(n & ...