My Blog List

[Leetcode Solution] Sqrt(x)

Analysis 

  • Use binary search to find the square root

Note

  • Just like calculate the average of two integer, it should use mid = low + (high - low)/2
  • because of needing calculating mid * mid, mid should be defined as long long
  • Each calculation must consider the overflow

Code


UPDATED AT 2ND PASS

No comments:

Post a Comment

Enter you comment