Skip to content

Instantly share code, notes, and snippets.

@olumidayy
Last active May 10, 2020 20:42
Show Gist options
  • Save olumidayy/6088998c043ebf7c2d346f835031135f to your computer and use it in GitHub Desktop.
Save olumidayy/6088998c043ebf7c2d346f835031135f to your computer and use it in GitHub Desktop.
day 10 Mobile
void main() {
print(is_perfect_square(500000000000000000));
}
bool is_perfect_square(int n) {
/** This function takes in a number and
* returns a boolean value indicating
* whether it is a perfect square or not */
var start = 0, end = n;
while (start <= end) {
var mid = (end + start) ~/ 2;
if (mid * mid == n) {
return true;
} else if (mid * mid > n) {
end = mid - 1;
} else {
start = mid + 1;
}
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment