Valid Perfect Square
Given a positive integer num, write a function which returns True if num is a perfect square else False. Note Do not use any built-in library function such as sqrt. Example 1 Input: 16 Output: true Example 2 Input: 14 Output: false Solution (naive) Java class Solution { public boolean isPerfectSquare(int num) { if (num == 1) return true; for (int i = 2; i < num; i++) { if (i * i == num) { return true; } if (i * i > num) { break; } } return false; } } Solution (Binary Search version 1) Let x be the square root, 1 < x < num/2 always holds true.