관리 메뉴

솜씨좋은장씨

[leetCode] 69. Sqrt(x) (Python) 본문

Programming/코딩 1일 1문제

[leetCode] 69. Sqrt(x) (Python)

솜씨좋은장씨 2020. 5. 19. 10:20
728x90
반응형

Implement int sqrt(int x).

Compute and return the square root of x, where x is guaranteed to be a non-negative integer.

Since the return type is an integer, the decimal digits are truncated and only the integer part of the result is returned.

 

Example 1:

Input: 4
Output: 2

Example 2:

Input: 8
Output: 2
Explanation: The square root of 8 is 2.82842..., and since 
             the decimal part is truncated, 2 is returned.

Solution

import math

class Solution:
    def mySqrt(self, x: int) -> int:
        answer = int(math.sqrt(x))
        return answer

 

SOMJANG/CODINGTEST_PRACTICE

1일 1문제 since 2020.02.07. Contribute to SOMJANG/CODINGTEST_PRACTICE development by creating an account on GitHub.

github.com

 

Comments