全站内容
hard
1092. Shortest Common Supersequence
#Problem Given two strings str1 and str2, return the shortest string that has both str1 and str2 as subsequences. If there are multiple valid strings, return any of them. A string s is a subsequence of string t if deleting some number of …
2296. Design a Text Editor
#Problem Design a text editor with a cursor that can do the following: Add text to where the cursor is. Delete text from where the cursor is (simulating the backspace key). Move the cursor either left or right. When deleting text, only …
1028. Recover a Tree From Preorder Traversal
#Problem We run a preorder depth-first search (DFS) on the root of a binary tree. At each node in this traversal, we output D dashes (where D is the depth of this node), then we output the value of this node. If the depth of a node is D, …
2209. Minimum White Tiles After Covering With Carpets
#Problem You are given a 0-indexed binary string floor, which represents the colors of tiles on a floor: floor[i] = '0' denotes that the iᵗʰ tile of the floor is colored black. On the other hand, floor[i] = '1' denotes that the iᵗʰ tile of …
1728. Cat and Mouse II
#Problem A game is played by a cat and a mouse named Cat and Mouse. The environment is represented by a grid of size rows x cols, where each element is a wall, floor, player (Cat, Mouse), or food. Players are represented by the characters …
827. Making A Large Island
#Problem You are given an n x n binary matrix grid. You are allowed to change at most one 0 to be 1. Return the size of the largest island in grid after applying this operation. An island is a 4-directionally connected group of 1s. …
2412. Minimum Money Required Before Transactions
#Problem You are given a 0-indexed 2D integer array transactions, where transactions[i] = [costᵢ, cashbackᵢ]. The array describes transactions, where each transaction must be completed exactly once in some order. At any given moment, you …
2920. Maximum Points After Collecting Coins From All Nodes
#Problem There exists an undirected tree rooted at node 0 with n nodes labeled from 0 to n - 1. You are given a 2D integer array edges of length n - 1, where edges[i] = [aᵢ, bᵢ] indicates that there is an edge between nodes aᵢ and bᵢ in the …
2218. Maximum Value of K Coins From Piles
#Problem There are n piles of coins on a table. Each pile consists of a positive number of coins of assorted denominations. In one move, you can choose any coin on top of any pile, remove it, and add it to your wallet. Given a list piles, …
42. Trapping Rain Water
#Problem Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it can trap after raining. https://leetcode.com/problems/trapping-rain-water/ Example 1: case1Input: height = …