Alice and Bob take turns playing a game, with Alice starting first.There are n stones arranged in a row. On each player's turn, they can remove either
Alex and Lee play a game with piles of stones. There are an even number of piles arranged in a row, and each pile has a positive integer number of st
Given an n-ary tree, return the level order traversal of its nodes' values.Nary-Tree input serialization is represented in their level order traversal
Given a string s, partition s such that every substring of the partition is a palindrome.Return the minimum cuts needed for a palindrome partitioning
Given an m x n matrix, return a new matrix answer where answerrow is the rank of matrixrow.The rank is an integer that represents how large an element
Given two non-negative integers, num1 and num2 represented as string, return the sum of num1 and num2 as a string.You must solve the problem without u
A binary string is monotone increasing if it consists of some number of 0's (possibly none), followed by some number of 1's (also possibly none).You a
Given an array of integers arr of even length, return true if and only if it is possible to reorder it such that arr2 \* i + 1 = 2 arr\[2 i] for eve
Given an array of strings strs, group the anagrams together. You can return the answer in any order.An Anagram is a word or phrase formed by rearrangi
Given an m x n integer matrix matrix, if an element is 0, set its entire row and column to 0's, and return the matrix.You must do it in place.Example
You are given several boxes with different colors represented by different positive numbers.You may experience several rounds to remove boxes until th
Given two strings s and t of lengths m and n respectively, return the minimum window substring of s such that every character in t (including duplicat
Given an integer array nums, handle multiple queries of the following type:Calculate the sum of the elements of nums between indices left and right in
Given a binary tree root, a node X in the tree is named good if in the path from root to X there are no nodes with a value greater than X.Return the n
A message containing letters from A-Z can be encoded into numbers using the following mapping:To decode an encoded message, all the digits must be gro
Given the root of a binary tree, split the binary tree into two subtrees by removing one edge such that the product of the sums of the subtrees is max
Given the root of a Binary Search Tree and a target number k, return true if there exist two elements in the BST such that their sum is equal to the g
A complex number can be represented as a string on the form "real+imaginaryi" where:Given two complex numbers num1 and num2 as strings, return a strin
Given a non-negative integer c, decide whether there're two integers a and b such that a2 + b2 = c.Example 1:Example 2:Example 3:Example 4:Example 5:C
One way to serialize a binary tree is to use preorder traversal. When we encounter a non-null node, we record the node's value. If it is a null node,
We have n jobs, where every job is scheduled to be done from startTimei to endTimei, obtaining a profit of profiti.You're given the startTime, endTime
Given a sorted integer array nums and an integer n, add/patch elements to the array such that any number in the range 1, n inclusive can be formed by
You are given an m x n matrix M initialized with all 0's and an array of operations ops, where opsi = aᵢ, bᵢ means Mx should be incremented by one for
Suppose an array of length n sorted in ascending order is rotated between 1 and n times. For example, the array nums = 0,1,2,4,5,6,7 might become:4,5,
You are given an integer array nums of length n where nums is a permutation of the numbers in the range 0, n - 1.You should build a set sk = {numsk, n
Given the head of a singly linked list, reverse the list, and return the reversed list.Example 1:Example 2:Example 3:Constraints:그동안 leetcode를 안 풀었더니
A newly designed keypad was tested, where a tester pressed a sequence of n keys, one at a time.You are given a string keysPressed of length n, where k
You are given a string s of lowercase English letters and an integer array shifts of the same length.Call the shift() of a letter, the next letter in
Given a string s, reverse the string according to the following rules:All the characters that are not English letters remain in the same position.All
Given a string text, you want to use the characters of text to form as many instances of the word "balloon" as possible.You can use each character in
Given a palindromic string of lowercase English letters palindrome, replace exactly one character with any lowercase English letter so that the result
The Tribonacci sequence Tn is defined as follows: T₀ = 0, T₁ = 1, T₂ = 1, and Tₙ₊₃ = Tₙ + Tₙ₊₁ + Tₙ₊₂ for n >= 0.Given n, return the value of Tₙ.Examp
Every valid email consists of a local name and a domain name, separated by the '@' sign. Besides lowercase letters, the email may contain one or more
Given an array of integers nums, half of the integers in nums are odd, and the other half are even.Sort the array so that whenever numsi is odd, i is
Given the head of a singly linked list and an integer k, split the linked list into k consecutive linked list parts.The length of each part should be
Given an integer array nums and an integer k, return true if it is possible to divide this array into k non-empty subsets whose sums are all equal.Exa
Given two strings text1 and text2, return the length of their longest common subsequence. If there is no common subsequence, return 0.A subsequence of
You are given row x col grid representing a map where gridi = 1 represents land and gridi = 0 represents water.Grid cells are connected horizontally/v
You are given an integer array nums. You are initially positioned at the array's first index, and each element in the array represents your maximum ju
You are climbing a staircase. It takes n steps to reach the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb t
The demons had captured the princess and imprisoned her in the bottom-right corner of a dungeon. The dungeon consists of m x n rooms laid out in a 2D
Given an integer array nums of length n where all the integers of nums are in the range 1, n and each integer appears once or twice, return an array o
Given an m x n grid of characters board and a string word, return true if word exists in the grid.The word can be constructed from letters of sequenti
Given the root of a binary tree, return the length of the diameter of the tree.The diameter of a binary tree is the length of the longest path between
We are playing the Guess Game. The game is as follows:I pick a number from 1 to n. You have to guess which number I picked.Every time you guess wrong,
Given two integers left and right that represent the range left, right, return the bitwise AND of all numbers in this range, inclusive.Example 1:Examp
A trie (pronounced as "try") or prefix tree is a tree data structure used to efficiently store and retrieve keys in a dataset of strings. There are va
Given an array of integers preorder, which represents the preorder traversal of a BST (i.e., binary search tree), construct the tree and return its ro
Given an integer n, return the least number of perfect square numbers that sum to n.A perfect square is an integer that is the square of an integer; i
You are given an array prices where pricesi is the price of a given stock on the ith day.Find the maximum profit you can achieve. You may complete as
Given the root of a binary tree and an integer targetSum, return the number of paths where the sum of the values along the path equals targetSum.The p
Given the root of a binary tree with unique values and the values of two different nodes of the tree x and y, return true if the nodes corresponding t
You are given an array prices where pricesi is the price of a given stock on the ith day.Find the maximum profit you can achieve. You may complete at
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.You are given two dist
Given an input string s, reverse the order of the words.A word is defined as a sequence of non-space characters. The words in s will be separated by a
Implement the RandomizedSet class:You must implement the functions of the class such that each function works in average O(1) time complexity.Example
Given a string s, sort it in decreasing order based on the frequency of the characters. The frequency of a character is the number of times it appears
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.Implement the MinStack class:Example 1:Constraints:간단
Suppose an array of length n sorted in ascending order is rotated between 1 and n times. For example, the array nums = 0,1,4,4,5,6,7 might become:Noti
Given the root of a complete binary tree, return the number of the nodes in the tree.According to Wikipedia, every level, except possibly the last, is
Given the root of a binary tree, invert the tree, and return its root.Example 1:Example 2:Example 3:Constraints:정말 쉬운 문제다.Binary Tree를 탐색하면서 좌・우 자식 노드
Given an array nums with n objects colored red, white, or blue, sort them in-place so that objects of the same color are adjacent, with the colors in
Given an integer array nums, return all the triplets \[numsi, numsj, numsk] such that i != j, i != k, and j != k, and numsi + numsj + numsk == 0.Notic
You are given a doubly linked list which in addition to the next and previous pointers, it could have a child pointer, which may or may not point to a
You are given the root of a binary tree containing digits from 0 to 9 only.Each root-to-leaf path in the tree represents a number.For example, the roo
Given the root of a binary tree, return the sum of all left leaves.Example 1:Example 2:Constraints:left leaf node의 합을 구하라는 문제다. Tree를 탐색해야 하기 때문에 재귀함수
Given a string s, consider all duplicated substrings: (contiguous) substrings of s that occur 2 or more times. The occurrences may overlap.Return any
You have n coins and you want to build a staircase with these coins. The staircase consists of k rows where the ith row has exactly i coins. The last
Given an integer n, return the number of structurally unique BST's (binary search trees) which has exactly n nodes of unique values from 1 to n.Exampl
Given an integer array nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements tha
Given two non-negative integers num1 and num2 represented as strings, return the product of num1 and num2, also represented as a string.Note: You must
With respect to a given puzzle string, a word is valid if both the following conditions are satisfied:Return an array answer, where answeri is the num
You are given an integer array prices where pricesi is the price of a given stock on the ith day.On each day, you may decide to buy and/or sell the st
Problem > Given an array of integers nums, you start with an initial positive value startValue. > In each iteration, you calculate the step by step su
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
Given an array of integers temperatures represents the daily temperatures, return an array answer such that answeri is the number of days you have to
Design the CombinationIterator class:Example 1:Constraints:알파벳이 정렬된 순서로 단 한 번만 등장하는 string과 이 알파벳을 조합하는 길이가 input으로 들어오는 클래스인 CombinationIterator를 디자인
Given a set of distinct positive integers nums, return the largest subset answer such that every pair (answeri, answerj) of elements in this subset sa
The Hamming distance between two integers is the number of positions at which the corresponding bits are different.Given two integers x and y, return
Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return the root node reference (possibly updated) of th
Given two integer arrays inorder and postorder where inorder is the inorder traversal of a binary tree and postorder is the postorder traversal of the
You are given a sorted array consisting of only integers where every element appears exactly twice, except for one element which appears exactly once.
Given an array nums of n integers where numsi is in the range 1, n, return an array of all the integers in the range 1, n that do not appear in nums.E
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).The robot can only move either down or right at any po
You are given an integer array of unique positive integers nums. Consider the following graph:There are nums.length nodes, labeled nums0 to numsnums.l
You are given two lists of closed intervals, firstList and secondList, where firstListi = starti, endi and secondListj = startj, endj. Each list of in
Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.A subarray is
Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if i
Given a directed acyclic graph (DAG) of n nodes labeled from 0 to n - 1, find all possible paths from node 0 to node n - 1 and return them in any orde
Given a list of accounts where each element accountsi is a list of strings, where the first element accountsi is a name, and the rest of the elements
Given an integer array nums, return an array answer such that answeri is equal to the product of all the elements of nums except numsi.The product of
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping yo
Given a binary array nums, return the maximum number of consecutive 1's in the array.Example 1:Example 2:Constraints:너무나 쉬운 문제다. 9월 문제인데 안 풀고 있다가 Rede
Given the head of a singly linked list, group all the nodes with odd indices together followed by the nodes with even indices, and return the reordere
Given an integer array nums, find a contiguous non-empty subarray within the array that has the largest product, and return the product.It is guarante
The thief has found himself a new place for his thievery again. There is only one entrance to this area, called root.Besides the root, each house has
Design an algorithm that accepts a stream of characters and checks if a suffix of these characters is a string of a given array of strings words.For e
We have n chips, where the position of the ith chip is positioni.We need to move all the chips to the same position. In one step, we can change the po
Given head which is a reference node to a singly-linked list. The value of each node in the linked list is either 0 or 1. The linked list holds the bi
Given the root of a binary tree, return the sum of every tree node's tilt.The tilt of a tree node is the absolute difference between the sum of all le
Given an array of non-negative integers arr, you are initially positioned at start index of the array. When you are at index i, you can jump to i + ar
The power of the string is the maximum length of a non-empty substring that contains only one unique character.Given a string s, return the power of s
You have two types of tiles: a 2 x 1 domino shape and a tromino shape. You may rotate these shapes.Given an integer n, return the number of ways to ti
Given a non-empty array nums containing only positive integers, find if the array can be partitioned into two subsets such that the sum of elements in
Given the root node of a binary search tree and two integers low and high, return the sum of values of all nodes with a value in the inclusive range l
Given the head of a singly linked list, sort the list using insertion sort, and return the sorted list's head.The steps of the insertion sort algorith
A tree is an undirected graph in which any two vertices are connected by exactly one path. In other words, any connected graph without simple cycles i
Given an m x n binary matrix filled with 0's and 1's, find the largest square containing only 1's and return its area.Example 1:Example 2:Example 3:Co
Given an array of distinct integers arr, find all pairs of elements with the minimum absolute difference of any two elements. Return a list of pairs i
Given an encoded string, return its decoded string.The encoding rule is: kencoded_string, where the encoded_string inside the square brackets is being
Given an array of digits which is sorted in non-decreasing order. You can write numbers using each digitsi as many times as we want. For example, if d
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 tha
You are given the head of a singly linked-list. The list can be represented as:Reorder the list to be on the following form:You may not modify the val
There are a total of numCourses courses you have to take, labeled from 0 to numCourses - 1. You are given an array prerequisites where prerequisitesi
Given an array of intervals where intervalsi = starti, endi, merge all overlapping intervals, and return an array of the non-overlapping intervals tha
The complement of an integer is the integer you get when you flip all the 0's to 1's and all the 1's to 0's in its binary representation.For example,
Given an array of points where pointsi = xi, yi represents a point on the X-Y plane and an integer k, return the k closest points to the origin (0, 0)
Given the head of a singly linked list, return the middle node of the linked list.If there are two middle nodes, return the second middle node.Example
You are given a perfect binary tree where all leaves are on the same level, and every parent has two children. The binary tree has the following defin
Given a positive integer k, you need to find the length of the smallest positive integer n such that n is divisible by k, and n only contains the digi
Given the root of a binary tree, find the maximum value v for which there exist different nodes a and b where v = |a.val - b.val| and a is an ancestor
In a town, there are n people labeled from 1 to n. There is a rumor that one of these people is secretly the town judge.If the town judge exists, then
You are given a list of songs where the ith song has a duration of timei seconds.Return the number of pairs of songs for which their total duration in
You are given n balloons, indexed from 0 to n - 1. Each balloon is painted with a number on it represented by an array nums. You are asked to burst al
The complement of an integer is the integer you get when you flip all the 0's to 1's and all the 1's to 0's in its binary representation.For example,
There is a car with capacity empty seats. The vehicle only drives east (i.e., it cannot turn around and drive west).You are given the integer capacity
Given a singly linked list, return a random node's value from the linked list. Each node must have the same probability of being chosen.Implement the
Given two binary strings a and b, return their sum as a binary string.Example 1:Example 2:Constraints:이진수를 더하는 원리만 알면 쉽게 풀 수 있는 문제다.주어진 string a와 b의 길
You are given the root of a binary tree where each node has a value 0 or 1. Each root-to-leaf path represents a binary number starting with the most s
You are given the root node of a binary search tree (BST) and a value to insert into the tree. Return the root node of the BST after the insertion. It
There are some spherical balloons taped onto a flat wall that represents the XY-plane. The balloons are represented as a 2D integer array points where
Given a pattern and a string s, find if s follows the same pattern.Here follow means a full match, such that there is a bijection between a letter in
You are given an array representing a row of seats where seatsi = 1 represents a person sitting in the ith seat, and seatsi = 0 represents that the it
You have a long flowerbed in which some of the plots are planted, and some are not. However, flowers cannot be planted in adjacent plots.Given an inte
Given the head of a linked list, return the node where the cycle begins. If there is no cycle, return null.There is a cycle in a linked list if there
Koko loves to eat bananas. There are n piles of bananas, the ith pile has pilesi bananas. The guards have gone and will come back in h hours.Koko can
There are n gas stations along a circular route, where the amount of gas at the ith station is gasi.You have a car with an unlimited gas tank and it c
Alice and Bob take turns playing a game, with Alice starting first.Initially, there are n stones in a pile. On each player's turn, that player makes a
We define the usage of capitals in a word to be right when one of the following cases holds:Example 1:Example 2:Constraints:대문자를 사용하는 세 가지 규칙을 주어진 단어가
Given two binary search trees root1 and root2, return a list containing all the integers from both trees sorted in ascending order.Example 1:Example 2
Design a data structure that supports adding new words and finding if a string matches any previously added string.Implement the WordDictionary class:
You are given an m x n integer grid accounts where accountsi is the amount of money the ith customer has in the jth bank
Given four integer arrays nums1, nums2, nums3, and nums4 all of length n, return the number of tuples (i, j, k, l) such that:Example 1:Example 2:Const
You are given an array prices where pricesi is the price of a given stock on the ith day.You want to maximize your profit by choosing a single day to
You are given two strings s and t.String t is generated by random shuffling string s and then add one more letter at a random position.Return the lett
Given an integer array nums sorted in non-decreasing order, remove some duplicates in-place such that each unique element appears at most twice. The r
Given an integer num, repeatedly add all its digits until the result has only one digit, and return it.Example 1:Example 2:Constraints:Follow up: Coul
Given an array of integers nums and an integer k, return the total number of continuous subarrays whose sum equals to k.Example 1:Example 2:Constraint
Given an array of integers nums and an integer k, return the number of unique k-diff pairs in the array.A k-diff pair is an integer pair (numsi, numsj
Problem >Given the root of a binary tree, return its maximum depth. > A binary tree's maximum depth is the number of nodes along the longest path from
Given a linked list, swap every two adjacent nodes and return its head. You must solve the problem without modifying the values in the list's nodes (i
Given a non-empty array of integers nums, every element appears twice except for one. Find that single one.You must implement a solution with a linear
Given an array of distinct integers candidates and a target integer target, return a list of all unique combinations of candidates where the chosen nu
Given string num representing a non-negative integer num, and an integer k, return the smallest possible integer after removing k digits from num.Exam
Given an array nums of size n, return the majority element.The majority element is the element that appears more than ⌊n / 2⌋ times. You may assume th
Given a string columnTitle that represents the column title as appear in an Excel sheet, return its corresponding column number.For example:A -> 1B ->
Given two version numbers, version1 and version2, compare them.Version numbers consist of one or more revisions joined by a dot '.'. Each revision con
You are given a sorted unique integer array nums.Return the smallest sorted list of ranges that cover all the numbers in the array exactly. That is, e
Problem > Given the root of a binary tree, return the maximum width of the given tree. > The maximum width of a tree is the maximum width among all le
Problem > Given a string s which represents an expression, evaluate this expression and return its value. > The integer division should truncate towar
Problem > Given an array of integers arr, return true if and only if it is a valid mountain array. > Recall that arr is a mountain array if and only i
Problem > Given an integer array nums, return the maximum result of nums[i] XOR nums[j], where 0 > > Example 1: > Input: nums = [3,10,5,25,2,8] Outp
Given two strings s and t, return true if s is a subsequence of t, or false otherwise.A subsequence of a string is a new string that is formed from th
Given an integer n, return an array ans of length n + 1 such that for each i (0 <= i <= n), ansi is the number of 1's in the binary representati
An integer array is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same
You are given an integer array nums. You want to maximize the number of points you get by performing the following operation any number of times:Retur
We stack glasses in a pyramid, where the first row has 1 glass, the second row has 2 glasses, and so on until the 100th row. Each glass holds one cup
You are given the heads of two sorted linked lists list1 and list2.Merge the two lists in a one sorted list. The list should be made by splicing toget
Given head, the head of a linked list, determine if the linked list has a cycle in it.There is a cycle in a linked list if there is some node in the l
You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, and each of their nodes conta
Problem >Given the head of a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. R
Given the head of a linked list, rotate the list to the right by k places.Example 1:Example 2:Constraints:주어진 리스트를 k번만큼 회전시킨 결과를 구하는 문제다.우선 head가 null
A linked list of length n is given such that each node contains an additional random pointer, which could point to any node in the list, or null.Const
Problem >Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. > An input string is
Problem >Given a string path, which is an absolute path (starting with a slash '/') to a file or directory in a Unix-style file system, convert it to
Given two integer arrays pushed and popped each with distinct values, return true if this could have been the result of a sequence of push and pop ope
Given a string s of '(' , ')' and lowercase English characters.Your task is to remove the minimum number of parentheses ( '(' or ')', in any positions
Write a function that reverses a string. The input string is given as an array of characters s.You must do this by modifying the input array in-place
You are given the root of a binary search tree (BST) and an integer val.Find the node in the BST that the node's value equals val and return the subtr
Given the root of a binary search tree, rearrange the tree in in-order so that the leftmost node in the tree is now the root of the tree, and every no
Given the root of a binary search tree, and an integer k, return the kth smallest value (1-indexed) of all the values of the nodes in the tree.Example
You are keeping score for a baseball game with strange rules. The game consists of several rounds, where the scores of past rounds may affect future r
Implement the BSTIterator class that represents an iterator over the in-order traversal of a binary search tree (BST):Notice that by initializing the
Design a HashSet without using any built-in hash table libraries.Implement MyHashSet class:Example 1:InputOutputExplanationConstraints:HashSet을 구현하라는
Design a HashMap without using any built-in hash table libraries.Implement the MyHashMap class:Example 1:InputOutputExplanationConstraints:key의 범위가 최대
You are given an integer array nums and an integer k.In one operation, you can pick two numbers from the array whose sum equals k and remove them from
Given two strings s and t, return true if they are equal when both are typed into empty text editors. '>Note that after backspacing an empty text, the
Given a 2D matrix matrix, handle multiple queries of the following type:Calculate the sum of the elements of matrix inside the rectangle defined by it
Problem Idea Solution Reference
Given the root of a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bot
Given the root of a binary tree, return the level order traversal of its nodes' values. (i.e., from left to right, level by level).Example 1:Example 2
You are given an integer array cost where costi is the cost of ith step on a staircase. Once you pay the cost, you can either climb one or two steps.Y
Given two integer arrays preorder and inorder where preorder is the preorder traversal of a binary tree and inorder is the inorder traversal of the sa
Given an integer numRows, return the first numRows of Pascal's triangle.In Pascal's triangle, each number is the sum of the two numbers directly above
Given two strings s and t, return true if t is an anagram of s, and false otherwise.An Anagram is a word or phrase formed by rearranging the letters o
Given two strings ransomNote and magazine, return true if ransomNote can be constructed by using the letters from magazine and false otherwise.Each le