Sqrt(x)

Implement int sqrt(int x). Compute and return the square root of x.

First thought: use long long, inefficient. Also, some conditions are unnecessary. However, the following code still passes the large judge.

Modified version: Thanks 六根清净 for providing a helpful binary search framework!

Comments

Popular posts from this blog

Maximum Gap

[ITint5] Maximum Subarray for a Circular Array

[CC150] Chapter 4 Trees and Graphs