Created
October 29, 2020 20:45
-
-
Save Ch-sriram/cb5e6b35ae6e82fe31daab2cbf662270 to your computer and use it in GitHub Desktop.
Number is Sparse or Not [TC: O(logN); SC: O(1)]
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
// Problem Link: https://practice.geeksforgeeks.org/problems/number-is-sparse-or-not-1587115620/1/ | |
bool isSparse(int n) { | |
for(int i = 0; i < 32; ++i) | |
if(((n >> i) & 3) == 3) | |
return false; | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Problem Link