1. 程式人生 > >leetcode Valid Perfect Square

leetcode Valid Perfect Square

leetcode Valid Perfect Square  題目:https://leetcode.com/problems/valid-perfect-square/

解題思路:利用Math.sqrt 獲得值是否等於強制Math.sqrt

public static void main(String[] args) {
		int num=16;
		boolean perfectSquare = isPerfectSquare(num);
		System.out.println(perfectSquare);

	}
	public static boolean isPerfectSquare(int num) {
		double sqrt = Math.sqrt(num);
		if(sqrt==(int)sqrt){
			return true;
		}
		return false;
	}