leetcode

Leetcode submissions
git clone git://git.laack.co/leetcode.git
Log | Files | Refs | README

power-of-two.dart (419B)


      1 //If a number is a power of two return true else return false.
      2 //This code has a time complexity of log(n) where n is the input value.
      3 //Time: 318ms Beats: 38.82%
      4 //Memory: 144.6MB Beats: 41.18%
      5 
      6 class Solution {
      7   bool isPowerOfTwo(int n) {
      8       int guess = 1;
      9       while(guess < n + 1){
     10           if(guess == n){
     11               return true;
     12           }
     13           guess = guess * 2;
     14       }
     15       return false;
     16   }
     17 }