Skip to content

Instantly share code, notes, and snippets.

@mukitul
Last active May 24, 2020 05:56
Show Gist options
  • Save mukitul/00a875d56039e55a8510c4664342edcf to your computer and use it in GitHub Desktop.
Save mukitul/00a875d56039e55a8510c4664342edcf to your computer and use it in GitHub Desktop.
This method checks perfect square in linear time
// 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