69. Sqrt(x)
Input: 4
Output: 2Input: 8
Output: 2
Explanation: The square root of 8 is 2.82842..., and since
the decimal part is truncated, 2 is returned.# @param {Integer} x
# @return {Integer}
require 'mathn'
def my_sqrt(x)
Math.sqrt(x).truncate(0)
endLast updated