Skip to main content

140 docs tagged with "LeetCode"

View All Tags

Add Binary

Given two binary strings a and b, return their sum as a binary string.

Add Strings

Given two non-negative integers, num1 and num2 represented as string, return the sum of num1 and num2 as a string.

Arranging Coins

You have n coins and you want to build a staircase with these coins.

Array Partition I

Given an integer array nums of 2n integers, group these integers into n pairs (a1, b1), (a2, b2), ..., (an, bn)

Assign Cookies

Assume you are an awesome parent and want to give your children some cookies.

Best Time Stock

You are given an array prices where prices[i] is the price of a given stock on the ith day.

Best Time Stock II

You are given an integer array prices where prices[i] is the price of a given stock on the ith day.

BST From Preorder

Given an array of integers preorder, which represents the preorder traversal of a BST (i.e., binary search tree),

Buddy String

Given two strings s and goal, return true if you can swap two letters in s so the result is equal to goal,

Can Place Flowers

You have a long flowerbed in which some of the plots are planted, and some are not.

Climbing Stairs

You are climbing a staircase. It takes n steps to reach the top.

Container With Most Water

Given n non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i, ai).

Contains Duplicate

Given an integer array nums, return true if any value appears at least twice in the array,

Contains Duplicate II

Given an integer array nums and an integer k, return true if there are two distinct indices i and j

Convert To Hex

Given an integer num, return a string representing its hexadecimal representation.

Count And Say

The count-and-say sequence is a sequence of digit strings defined by the recursive formula:

Counting Bits

Given an integer n, return an array ans of length n + 1 such that for each i (0 <= i <= n),

Cousins Binary Tree

Given the root of a binary tree with unique values and the values of two different nodes of the tree x and y,

Custom Sort String

You are given two strings order and s. All the words of order are unique

Daily Temperatures

Given an array of integers temperatures represents the daily temperatures, return an array answer

Day Of The Year

Given a string date representing a Gregorian calendar date formatted as YYYY-MM-DD, return the day number of the year.

Degree Of An Array

Given a non-empty array of non-negative integers nums, the degree of this array is defined as the maximum frequency of any one of its elements.

Design Hash Map

Design a HashMap without using any built-in hash table libraries:

Detect Capital

We define the usage of capitals in a word to be right when one of the following cases holds:

Divide Two Integers

Given two integers dividend and divisor, divide two integers without using multiplication, division, and mod operator.

Excel Sheet Column Title

Given an integer columnNumber, return its corresponding column title as it appears in an Excel sheet.

Find All Anagrams

Given two strings s and p, return an array of all the start indices of p's anagrams in s.

Find Duplicate Number

Given an array of integers nums containing n + 1 integers where each integer is in the range [1, n] inclusive.

First Bad Version

Suppose you have n versions [1, 2, ..., n] and you want to find out the first bad one,

First Unique Character

Given a string s, find the first non-repeating character in it and return its index. If it does not exist, return -1.

Format Phone Number

Given a phone number should format in the form of abc-def-ijk. Last two part can be of 2 digits

Generate Parentheses

Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.

Hamming Distance

The Hamming distance between two integers is the number of positions at which the corresponding bits are different.

Happy Number

Write an algorithm to determine if a number n is happy.

Is Subsequence

Given two strings s and t, return true if s is a subsequence of t, or false otherwise.

Island Perimeter

You are given row x col grid representing a map where gridi = 1 represents land and gridi = 0 represents water.

K Diff Pairs

Given an array of integers nums and an integer k, return the number of unique k-diff pairs in the array.

Keyboard Row

Given an array of strings words, return the words that can be typed

Length Of Last Word

Given a string s consisting of some words separated by some number of spaces, return the length of the last word in the string.

License Key Formatting

You are given a license key represented as a string s that consists of only alphanumeric characters and dashes.

Linked List Cycle

Given head, the head of a linked list, determine if the linked list has a cycle in it.

Longest Common Prefix

Write a function to find the longest common prefix string amongst an array of strings.

Max Area Of Island

You are given an m x n binary matrix grid. An island is a group of 1's (representing land)

Max Number Of Balloons

Given a string text, you want to use the characters of text to form as many instances of the word "balloon" as possible.

Max Product Sub Array

Given an integer array nums, find a contiguous non-empty subarray within the array that has the largest product,

Max Subarray

Given an integer array nums, find the contiguous subarray (containing at least one number)

Min Stack

Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.

Missing Number

Given an array nums containing n distinct numbers in the range [0, n],

Move Zeroes

Given an integer array nums, move all 0's to the end of it while maintaining

Next Greater Element

The next greater element of some element x in an array is the first greater element that is to the right of x in the same array.

Next Greater Element II

Given a circular integer array nums (i.e., the next element of nums[nums.length - 1] is nums[0]),

Nim Game

You are playing the following Nim Game with your friend:

Number Of1Bits

Write a function that takes an unsigned integer and returns the number of '1' bits it has (also known as the Hamming weight).

Pascal Triangle

Given an integer numRows, return the first numRows of Pascal's triangle.

Pascal Triangle II

Given an integer rowIndex, return the rowIndexth (0-indexed) row of the Pascal's triangle.

Path Sum

Given the root of a binary tree and an integer targetSum,

Plus One

You are given a large integer represented as an integer array digits, where each digits[i]

Power Of4

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

Range Sum Query

Given an integer array nums, handle multiple queries of the following type:

Ransom Note

Given two stings ransomNote and magazine, return true if ransomNote can be constructed from magazine and false otherwise.

Regions Cut By Slashes

An n x n grid is composed of 1 x 1 squares where each 1 x 1 square consists of a '/', '\', or blank space ' '.

Reorder List

You are given the head of a singly linked-list. The list can be represented as L0 → L1 → … → Ln - 1 → Ln

Reverse Bits

Reverse bits of a given 32 bits unsigned integer.

Reverse String

Write a function that reverses a string. The input string is given as an array of characters s.

Reverse String II

Given a string s and an integer k, reverse the first k characters for every 2k characters counting

Reverse Vowel

Given a string s, reverse only all the vowels in the string and return it.

Reverse Words

You are given a character array containing a set of words separated by whitespace.

Roman To Integer

Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.

Rotate Image

You are given an n x n 2D matrix representing an image, rotate the image by 90 degrees (clockwise).

Same Tree

Given the roots of two binary trees p and q, write a function to check if they are the same or not.

Search Range

Given an array of integers nums sorted in non-decreasing order, find the starting and ending position of

Set Mismatch

You have a set of integers s, which originally contains all the numbers from 1 to n.

Simplified Fraction

Given an integer n, return a list of all simplified fractions between 0 and 1 (exclusive)

Single Number

Given a non-empty array of integers nums, every element appears twice except for one. Find that single one.

Single Number II

Given an integer array nums where every element appears three times except for one, which appears exactly once.

Single Number III

Given an integer array nums, in which exactly two elements appear only once and

Sort Linked List

Given the head of a linked list, return the list after sorting it in ascending order.

Spiral Matrix

Given an m x n matrix, return all elements of the matrix in spiral order.

Spiral Matrix II

Given a positive integer n, generate an n x n matrix filled with elements from 1 to n^2 in spiral order.

Sqrtx

Given a non-negative integer x, compute and return the square root of x.

Symmetric Tree

Given the root of a binary tree, check whether it is a mirror of itself (i.e., symmetric around its center).

Three Sum Closest

Given an integer array nums of length n and an integer target, find three integers in nums such that the sum is closest to target.

Top K Frequent

Given an integer array nums and an integer k, return the k most frequent elements.

Total Hamming Distance

The Hamming distance between two integers is the number of positions at which the corresponding bits are different.

Two Sum II

Given a 1-indexed array of integers numbers that is already sorted in non-decreasing order,

Ugly Number

An ugly number is a positive integer whose prime factors are limited to 2, 3, and 5.

Unique Paths

A robot is located in the top-left corner of a m x n grid (marked 'Start' in the diagram below).

Unique Paths II

A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).

Valid Anagram

Given two strings s and t, return true if t is an anagram of s, and false otherwise.

Valid Palindrome

Given a string s, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.

Wildcard Search DS

Design a data structure that supports adding new words and finding if a string matches any previously added string.

Word Break

Given a string s and a dictionary of strings wordDict, return true if s can be segmented into a

Word Pattern

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

Word Search

Given an m x n grid of characters board and a string word, return true if word exists in the grid.

Zig Zag Conversion

The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: