Last active
May 24, 2020 05:56
-
-
Save mukitul/00a875d56039e55a8510c4664342edcf to your computer and use it in GitHub Desktop.
This method checks perfect square in linear time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// this method will return 1 if N is valid perfect square number otherwise -1 | |
public static int validPerfectSquare(int N) { | |
if (N == 1) | |
return 1; | |
for (int i = 2; i <= N; i++) { | |
if (i * i == N) { | |
return 1; | |
} | |
} | |
return -1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment