feat: 2025-10-27打卡
This commit is contained in:
23
69.sqrt-x.java
Normal file
23
69.sqrt-x.java
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* @lc app=leetcode id=69 lang=java
|
||||||
|
*
|
||||||
|
* [69] Sqrt(x)
|
||||||
|
*/
|
||||||
|
|
||||||
|
// @lc code=start
|
||||||
|
class Solution {
|
||||||
|
public int mySqrt(int x) {
|
||||||
|
long l = 0, r = Integer.MAX_VALUE;
|
||||||
|
while(r-l > 1) {
|
||||||
|
long mid = l + (r-l)/2;
|
||||||
|
if(mid * mid <= (long)x) {
|
||||||
|
l = mid;
|
||||||
|
} else {
|
||||||
|
r = mid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (int)l;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// @lc code=end
|
||||||
|
|
||||||
Reference in New Issue
Block a user