0%

Word Pattern – LeetCode 290

Problem

Description

Given a pattern and a string str, find if str follows the same pattern.

Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word in str.

Read more »

Move Zeroes – LeetCode 283

Problem

Description

Given an array nums, write a function to move all 0’s to the end of it while maintaining the relative order of the non-zero elements.

Read more »

First Bad Version – LeetCode 278

Problem

Description

You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed based on the previous version, all the versions after a bad version are also bad.

Suppose you have n versions [1, 2, …, n] and you want to find out the first bad one, which causes all the following ones to be bad.+

You are given an API bool isBadVersion(version) which will return whether version is bad. Implement a function to find the first bad version. You should minimize the number of calls to the API.

Read more »

Paint Fence – LeetCode 276

Problem

Description

There is a fence with n posts, each post can be painted with one of the k colors.

You have to paint all the posts such that no more than two adjacent fence posts have the same color.

Return the total number of ways you can paint the fence.

Note: n and k are non-negative integers.

Read more »

Strobogrammatic NumberClosest Binary Search Tree Value – LeetCode 270

Problem

Description

Given a non-empty binary search tree and a target value, find the value in the BST that is closest to the target.

Read more »

Missing Number – LeetCode 268

Problem

Description

Given an array containing n distinct numbers taken from 0, 1, 2, …, n, find the one that is missing from the array.

Read more »

Palindrome Permutation – LeetCode 266

Problem

Description

Given a string, determine if a permutation of the string could form a palindrome.

Read more »

Ugly Number – LeetCode 263

Problem

Description

Write a program to check whether a given number is an ugly number.

Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is not ugly since it includes another prime factor 7.

Note that 1 is typically treated as an ugly number.

Read more »

Add Digits – LeetCode 258

Problem

Description

Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.

Read more »

Binary Tree Paths – LeetCode 257

Problem

Description

Given a binary tree, return all root-to-leaf paths.

Read more »