-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSolution.java
More file actions
32 lines (29 loc) · 766 Bytes
/
Solution.java
File metadata and controls
32 lines (29 loc) · 766 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package sqrtx;
/**
* Implement int sqrt(int x).
* <p>
* Compute and return the square root of x, where x is guaranteed to be a non-negative integer.
* <p>
* Since the return type is an integer, the decimal digits are truncated and only the integer part of the result is returned.
* <p>
* Example 1:
* <p>
* Input: 4
* Output: 2
* Example 2:
* <p>
* 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) {
return (int) Math.sqrt(x);
}
}
/*
Runtime: 1 ms, faster than 100.00% of Java online submissions for Sqrt(x).
Memory Usage: 36.4 MB, less than 5.00% of Java online submissions for Sqrt(x).
Next challen
*/