Square root of x (binary search implementation)
class Solution {
public int mySqrt(int x) {
int l = 0, r = x, ans = -1;
while (l <= r) {
int mid = (l + r)/ 2;
if ((long) mid * mid <= x) {
ans = mid;
l = mid + 1;
} else {
r = mid - 1;
}
}
return ans;
}
}
Read More:
- Solve the problem of incomplete search results of outlook search function
- Python’s direct method for solving linear equations (5) — square root method for solving linear equations
- PySpark ERROR Shell: Failed to locate the winutils binary in the hadoop binary path
- Nexus 5x unlock bootloader + root
- Two kinds of errors caused by root / lack of execution permission x
- Lingerror last 2 dimensions of the array must be square
- The method of constructing even order magic square (n = 4 * m)
- RuntimeError: Expected hidden[0] size (x, x, x), got(x, x, x)
- In machine learning, the prediction errors in sklearn, such as mean square error, etc
- Python judge perfect square number
- Video prediction beyond mean square error
- [Solved] emulator: glteximage2d: got err pre 🙁 0x502 internal 0x1908 format 0x1908 type 0x1401
- Apache Groovy——java.lang.NoSuchMethodError: x.x.x: method <init>()V not found
- CLP: error: getaddrinfo enotfound http://x.x.x.x/
- RMSE(Root Mean Squared Error) & RMSLE(Root Mean Squared Logarithmic Error)
- [study notes] a quick search of latex mathematical symbols
- About java “Error: bad binary operator types”
- Implementation of multithread sequential alternate execution by using lock in Java
- How to search files or folders in Ubuntu
- module ‘win32com.gen_py.00020813-0000-0000-C000-000000000046x0x1x9‘ has no attribute ‘CLSIDToClassMa