博客
关于我
#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/

你可能感兴趣的文章