码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 69. Sqrt(x)x 的平方根


     

    Given a non-negative integer x, compute and return the square root of x.

    给你一个非负整数 x ,计算并返回 x 的 算术平方根 。

    Since the return type is an integer, the decimal digits are truncated, and only the integer part of the result is returned.

    由于返回类型是整数,结果只保留 整数部分 ,小数部分将被 舍去 。

    Note: You are not allowed to use any built-in exponent function or operator, such as pow(x, 0.5) or x ** 0.5.

    注意:不允许使用任何内置指数函数和算符,例如 pow(x, 0.5) 或者 x ** 0.5 。

    Example 1:示例 1:

    Input: x = 4
    Output: 2


    Example 2:示例 2:

    Input: x = 8
    Output: 2


    Explanation: The square root of 8 is 2.82842..., and since the decimal part is truncated, 2 is returned.
     

    Constraints:提示:

    0 <= x <= 2^{31} - 1

    C语言:

    1. int mySqrt(int x){
    2. long max=1;
    3. while(max*max<=x)
    4. {
    5. max++;
    6. }
    7. return max-1;
    8. }

    执行结果:通过

    执行用时:24 ms, 在所有 C 提交中击败了10.23%的用户

    内存消耗:5.5 MB, 在所有 C 提交中击败了45.56%的用户

    通过测试用例:1017 / 1017

  • 相关阅读:
    linux分区扩容
    java毕业设计项目选题基于SSM+JSP+MYSQL+H-UI 实现的校园食堂点餐|订餐系统
    linux挂载u盘及卸载
    电脑重装系统后鼠标动不了该怎么解决
    2023软件测试的4个技术等级,你在哪个级别?
    Python Gui之tkinter(下)
    5G消息.
    springcloud feign配置及调用
    Java开发备战 - JavaSe(基础篇)
    python安装robotframework的一些常见的错误
  • 原文地址:https://blog.csdn.net/DXB2021/article/details/126059809
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号