Alexandre Pokhodoun

Search

SearchSearch

Recent Writing

  • Longest increasing subsequence

    May 17, 2025

  • Minimum operations to make a subsequence

    May 17, 2025

  • Shortest subarray with sum at least k

    May 16, 2025

  • Count the number of fair pairs

    May 15, 2025

  • The skyline problem

    Apr 27, 2025

See 250 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

  • Longest increasing subsequence

    May 17, 2025

  • Minimum operations to make a subsequence

    May 17, 2025

  • Shortest subarray with sum at least k

    May 16, 2025

  • Count the number of fair pairs

    May 15, 2025

  • The skyline problem

    Apr 27, 2025

See 250 more →

Graph View

Backlinks

  • No backlinks found

  • GitHub
  • Linkedin