Skip to content
Logo
Terrible Whiteboard

Solving Algorithms One Whiteboard at a Time

  • Home
  • Blog
  • Contact
  • Coupons and Discounts
  • Search

Power of Two | LeetCode 231

Uncategorized

AFFILIATE LINKS

Great resource I use to learn algorithms.
40% off Tech Interview Pro: http://techinterviewpro.com/terriblewhiteboard
20% off CoderPro: http://coderpro.com/terriblewhiteboard


Here is the full implementation.

/**
 * @param {number} n
 * @return {boolean}
 */
let isPowerOfTwo = function(n) {
    if (n < 1) {
        return false;
    }
    
    let powerOfTwo = 1;
    
    while (powerOfTwo < n) {
        powerOfTwo *= 2;
    }
    
    return powerOfTwo === n;
};

Post navigation

← Previous Post
Next Post →
Udemy Course: Data Structures and Algorithms

Recent Posts

  • Add Two Numbers | LeetCode 2
  • Odd Even Linked List | LeetCode 328
  • Find the Town Judge | LeetCode 997
  • Jump Game | LeetCode 55
  • Partition Equal Subset Sum | LeetCode 416

Archives

  • May 2020
  • April 2020
  • March 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019

Categories

  • Uncategorized
terriblewhiteboard@gmail.com
Copyright © 2025 Terrible Whiteboard