Check Perfect Square
Given a non-negative integer n, determine whether it is a perfect square. A perfect square is an integer that is the square of an integer; in other words, it is the product of some integer with itself.
For example, 1, 4, 9, and 16 are perfect squares while 3, 10, and 17 are not.
[ 1 ]
Explanation. 1 is 1 squared (1x1), therefore it is a perfect square.
[ 16 ]
Explanation. 16 is 4 squared (4x4), therefore it is a perfect square.
[ 14 ]
Explanation. 14 cannot be expressed as the square of any integer.
[ 25 ]
Explanation. 25 is 5 squared (5x5), therefore it is a perfect square.
[ 26 ]
Explanation. 26 cannot be expressed as the square of any integer.
Follow-up: Can this problem be solved without using the built-in square root function? What would be the implications of that approach on the complexity of the algorithm?
Input will be a non-negative integer.
- Views
- 4