博客
关于我
#Leetcode# 69. Sqrt(x)
阅读量:797 次
发布时间:2023-04-04

本文共 976 字,大约阅读时间需要 3 分钟。

Implement int sqrt(int x).

Compute and return the square root of x, where x is guaranteed to be a non-negative integer.

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

Example 1:

Input: 4
Output: 2

Example 2:

Input: 8
Output: 2

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

代码:

class Solution {public:    int mySqrt(int x) {        int ans = (int)sqrt(x);        return ans;    }}

以上HTML代码经过优化,去除了多余的div标签和不必要的结构,保持了内容的完整性和可读性。代码块通过<div class="cnblogs_Highlighter">包裹,方便与其他样式进行区分。文章内容经过重新组织,使其更加简洁明了,同时保留了技术细节和示例信息。

转载地址:http://tnrfk.baihongyu.com/

你可能感兴趣的文章
Objective-C实现最小值滤波(附完整源码)
查看>>
Objective-C实现最小公倍数LCM算法(附完整源码)
查看>>
Objective-C实现最小生成树 boruvka算法(附完整源码)
查看>>
Objective-C实现最小编辑距离问题算法(附完整源码)
查看>>
Objective-C实现最小路径和算法(附完整源码)
查看>>
Objective-C实现最快的归并排序算法(附完整源码)
查看>>
Objective-C实现最短路径Dijsktra算法(附完整源码)
查看>>
Objective-C实现最短路径Dijsktra算法(附完整源码)
查看>>
Objective-C实现最短路径广度优先搜索算法(附完整源码)
查看>>
Objective-C实现最近点对问题(附完整源码)
查看>>
Objective-C实现最长公共子序列算法(附完整源码)
查看>>
Objective-C实现最长回文子串算法(附完整源码)
查看>>
Objective-C实现最长回文子序列算法(附完整源码)
查看>>
Objective-C实现最长子数组算法(附完整源码)
查看>>
Objective-C实现最长字符串链(附完整源码)
查看>>
Objective-C实现最长递增子序列算法(附完整源码)
查看>>
Objective-C实现有向图和无向加权图算法(附完整源码)
查看>>
Objective-C实现有序表查找算法(附完整源码)
查看>>
Objective-C实现有限状态机(附完整源码)
查看>>
Objective-C实现有限状态自动机FSM(附完整源码)
查看>>