69. Sqrt(x) Easy

@problem@discussion
#Math#Binary Search



1/**
2 * [69] Sqrt(x)
3 *
4 * Given a non-negative integer x, compute and return the square root of x.
5 * Since the return type is an integer, the decimal digits are truncated, and only the integer part of the result is returned.
6 * Note: You are not allowed to use any built-in exponent function or operator, such as pow(x, 0.5) or x ** 0.5.
7 *  
8 * Example 1:
9 * 
10 * Input: x = 4
11 * Output: 2
12 * 
13 * Example 2:
14 * 
15 * Input: x = 8
16 * Output: 2
17 * Explanation: The square root of 8 is 2.82842..., and since the decimal part is truncated, 2 is returned.
18 *  
19 * Constraints:
20 * 
21 * 	0 <= x <= 2^31 - 1
22 * 
23 */
24pub struct Solution {}
25
26// problem: https://leetcode.com/problems/sqrtx/
27// discuss: https://leetcode.com/problems/sqrtx/discuss/?currentPage=1&orderBy=most_votes&query=
28
29// submission codes start here
30
31impl Solution {
32    pub fn my_sqrt(x: i32) -> i32 {
33        0
34    }
35}
36
37// submission codes end
38
39#[cfg(test)]
40mod tests {
41    use super::*;
42
43    #[test]
44    fn test_69() {
45    }
46}
47


Back
© 2025 bowen.ge All Rights Reserved.