本文主要是介绍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;}
这篇关于leetcode Valid Perfect Square的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!