# Power of Two 🎐

Question

Given an integer `n`, return `true` if it is a power of two. Otherwise, return `false`.

An integer `n` is a power of two, if there exists an integer `x` such that `n == 2x`.

Example 1:

`Input: n = 1Output: trueExplanation: 20 = 1`

Example 2:

`Input: n = 16Output: trueExplanation: 24 = 16`

Example 3:

`Input: n = 3Output: false`

Constraints:

• `-231 <= n <= 231 - 1`

# Solution

Time Complexity O(log n)

Space Complexity O(log n)

Time Complexity O(log n)

Space Complexity O(1)

Do you see that green follow button? 🐌

--

--

# Remove Linked List Elements 🧤

Question

Given the `head` of a linked list and an integer `val`, remove all the nodes of the linked list that has `Node.val == val`, and return the new head.

Example 1:

`Input: head = [1,2,6,3,4,5,6], val = 6Output: [1,2,3,4,5]`

Example 2:

`Input: head = [], val = 1Output…`

--

--

# Pow(x, n) 🧶

Question

Implement pow(x, n), which calculates `x` raised to the power `n` (i.e., `xn`).

Example 1:

`Input: x = 2.00000, n = 10Output: 1024.00000`

Example 2:

`Input: x = 2.10000, n = 3Output: 9.26100`

Example 3:

`Input: x = 2.00000, n = -2Output: 0.25000Explanation: 2-2 = 1/22 = 1/4 = 0.25`

Constraints:

• `-100.0 < x < 100.0`
• `-231 <= n <= 231-1`
• `-104 <= xn <= 104`

# Solution

Time Complexity O(n)

Space Complexity O(1)

Time Complexity O(log n)

Space Complexity O(log n)

Time Complexity O(log n)

Space Complexity O(1)

Do you see that green follow button? 🐌

--

--

# Set Matrix Zeroes 🐢

Question

Given an `m x n` integer matrix `matrix`, if an element is `0`, set its entire row and column to `0`'s.

You must do it in place.

Example 1:

`Input: matrix = [[1,1,1],[1,0,1],[1,1,1]]Output: [[1,0,1],[0,0,0],[1,0,1]]`

Example 2:

--

--

# Reverse Linked List 🌋

Question

Given the `head` of a singly linked list, reverse the list, and return the reversed list.

Example 1:

`Input: head = [1,2,3,4,5]Output: [5,4,3,2,1]`

Example 2:

--

--

# 3Sum 👠

Question

Given an integer array nums, return all the triplets `[nums[i], nums[j], nums[k]]` such that `i != j`, `i != k`, and `j != k`, and `nums[i] + nums[j] + nums[k] == 0`.

Notice that the solution set must not contain duplicate triplets.

Example 1:

`Input: nums = [-1,0,1,2,-1,-4]Output: [[-1,-1,2],[-1,0,1]]`

Example 2:

`Input: nums = []Output: []`

Example 3:

`Input: nums = [0]Output: []`

Constraints:

• `0 <= nums.length <= 3000`
• `-105 <= nums[i] <= 105`

# Solution

Time Complexity O(n³)

Space Complexity O(d) where d is the number of possible sets

Time Complexity O(n²)

Space Complexity O(n + d) where d is the number of possible sets

Do you see that green follow button? 🐌

--

--