Last active
May 10, 2020 20:42
-
-
Save olumidayy/6088998c043ebf7c2d346f835031135f to your computer and use it in GitHub Desktop.
day 10 Mobile
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
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