Advertisement
vaibhav1906

isPowerOfTwo

Dec 18th, 2021
1,307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.32 KB | None | 0 0
  1. class Solution {
  2. public:
  3.    
  4.     bool helper(int n){
  5.        
  6.         if(n==1) return true;
  7.         if(n%2==1) return false;
  8.        
  9.         return helper(n/2);
  10.        
  11.     }
  12.    
  13.     bool isPowerOfTwo(int n) {
  14.        
  15.         if(n<=0)return false;
  16.        
  17.         return helper(n);
  18.        
  19.     }
  20. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement