MCPcopy Create free account
hub / github.com/PrajaktaSathe/Java / isPerfectSquare

Method isPerfectSquare

Programs/isValidPerfectSquare.java:4–14  ·  view source on GitHub ↗
(int num)

Source from the content-addressed store, hash-verified

2
3class ValidPerfectSquare {
4 public boolean isPerfectSquare(int num) {
5 long high = (long) num+1;
6 long low = -1;
7 while(low!=high-1){
8 long mid = (low+high)/2;
9 if(mid*mid==num) return true;
10 else if(mid*mid>num) high = mid;
11 else low = mid;
12 }
13 return false;
14 }
15}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected