Alexandre Pokhodoun

Search

SearchSearch

Recent Writing

  • Trapping rain water II

    May 22, 2025

  • Allocate mailboxes

    May 21, 2025

  • Find longest self contained substring

    May 20, 2025

  • Maximum number of groups with increasing length

    May 19, 2025

  • Longest increasing subsequence

    May 17, 2025

See 254 more →

Home

❯

leetcode

❯

Power of 2

Power of 2

May 15, 20241 min read

Link: https://leetcode.com/problems/power-of-two/

Solution:

Topics: bitwise, Pseudo palindromic paths in a binary tree

Intuition
This is a bitwise problem using the & operator, see Pseudo palindromic paths in a binary tree for a detailed explanation on it

Implementation

def is_power(n):
	if n == 0:
		return False
	return n & (-n) == n
 
#time: o(1)
#memory: o(1)

Visual

review

Recent Writing

  • Trapping rain water II

    May 22, 2025

  • Allocate mailboxes

    May 21, 2025

  • Find longest self contained substring

    May 20, 2025

  • Maximum number of groups with increasing length

    May 19, 2025

  • Longest increasing subsequence

    May 17, 2025

See 254 more →

Graph View

Backlinks

  • No backlinks found

  • GitHub
  • Linkedin