<Code author="Calf" />
224. Basic Calculator
#Problem Given a string s representing a valid expression, implement a basic calculator to evaluate it, and return the result of the evaluation. Note: You are not allowed to use any built-in function which evaluates strings as mathematical …
2415. Reverse Odd Levels of Binary Tree
#Problem Given the root of a perfect binary tree, reverse the node values at each odd level of the tree. For example, suppose the node values at level 3 are [2,1,3,4,7,11,29,18], then it should become [18,29,11,7,4,3,1,2]. Return the root …
3138. Minimum Length of Anagram Concatenation
#Problem You are given a string s, which is known to be a concatenation of anagrams of some string t. Return the minimum possible length of the string t. An anagram is formed by rearranging the letters of a string. For example, “aab”, …
337. House Robber III
#Problem 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 one and only one parent house. After a tour, the smart thief realized that all …
43. Multiply Strings
#Problem 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 not use any built-in BigInteger library or convert the inputs to integer …
3389. Minimum Operations to Make Character Frequencies Equal
#Problem You are given a string s. A string t is called good if all characters of t occur the same number of times. You can perform the following operations any number of times: Delete a character from s. Insert a character in s. Change a …
769. Max Chunks To Make Sorted
#Problem You are given an integer array arr of length n that represents a permutation of the integers in the range [0, n - 1]. We split arr into some number of chunks (i.e., partitions), and individually sort each chunk. After concatenating …
3285. Find Indices of Stable Mountains
#Problem There are n mountains in a row, and each mountain has a height. You are given an integer array height where height[i] represents the height of mountain i, and an integer threshold. A mountain is called stable if the mountain just …
496. Next Greater Element I
#Problem 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 distinct 0-indexed integer arrays nums1 and nums2, where nums1 is a subset of nums2. …
503. Next Greater Element II
#Problem Given a circular integer array nums (i.e., the next element of nums[nums.length - 1] is nums[0]), return the next greater number for every element in nums. The next greater number of a number x is the first greater number to its …
739. Daily Temperatures
#Problem Given an array of integers temperatures represents the daily temperatures, return an array answer such that answer[i] is the number of days you have to wait after the iᵗʰ day to get a warmer temperature. If there is no future day …
1475. Final Prices With a Special Discount in a Shop
#Problem You are given an integer array prices where prices[i] is the price of the iᵗʰ item in a shop. There is a special discount for items in the shop. If you buy the iᵗʰ item, then you will receive a discount equivalent to prices[j] …
714. Best Time to Buy and Sell Stock with Transaction Fee
#Problem You are given an array prices where prices[i] is the price of a given stock on the iᵗʰ day, and an integer fee representing a transaction fee. Find the maximum profit you can achieve. You may complete as many transactions as you …
309. Best Time to Buy and Sell Stock with Cooldown
#Problem You are given an array prices where prices[i] is the price of a given stock on the iᵗʰ day. Find the maximum profit you can achieve. You may complete as many transactions as you like (i.e., buy one and sell one share of the stock …
122. Best Time to Buy and Sell Stock II
#Problem You are given an integer array prices where prices[i] is the price of a given stock on the iᵗʰ day. On each day, you may decide to buy and/or sell the stock. You can only hold at most one share of the stock at any time. However, …
188. Best Time to Buy and Sell Stock IV
#Problem You are given an integer array prices where prices[i] is the price of a given stock on the iᵗʰ day, and an integer k. Find the maximum profit you can achieve. You may complete at most k transactions: i.e. you may buy at most k …
123. Best Time to Buy and Sell Stock III
#Problem You are given an array prices where prices[i] is the price of a given stock on the iᵗʰ day. Find the maximum profit you can achieve. You may complete at most two transactions. Note: You may not engage in multiple transactions …
3291. Minimum Number of Valid Strings to Form Target I
#Problem You are given an array of strings words and a string target. A string x is called valid if x is a prefix of any string in words. A prefix of a string is a substring that starts from the beginning of the string and extends to any …
3292. Minimum Number of Valid Strings to Form Target II
3291. Minimum Number of Valid Strings to Form Target I 的进阶版,题目一模一样,但 words 的长度从 5 * 10³ 增加到 5 * 10⁵,target 的长度从 5 * 10³ 增加到 5 * 10⁴。 如果按 problem 3291 中 O(n²) 复杂度的 trie 树 + 动态规划是无法 AC 的,需要用更快的 AC 自动机。
3213. Construct String with Minimum Cost
#Problem You are given a string target, an array of strings words, and an integer array costs, both arrays of the same length. Imagine an empty string s. You can perform the following operation any number of times (including zero): Choose …
2182. Construct String With Repeat Limit
#Problem You are given a string s and an integer repeatLimit. Construct a new string repeatLimitedString using the characters of s such that no letter appears more than repeatLimit times in a row. You do not have to use all characters from …
1792. Maximum Average Pass Ratio
#Problem There is a school that has classes of students and each class will be having a final exam. You are given a 2D integer array classes, where classes[i] = [passᵢ, totalᵢ]. You know beforehand that in the iᵗʰ class, there are totalᵢ …
1338. Reduce Array Size to The Half
#Problem You are given an integer array arr. You can choose a set of integers and remove all the occurrences of these integers in the array. Return the minimum size of the set so that at least half of the integers of the array are removed. …
2809. Minimum Time to Make Array Sum At Most x
#Problem You are given two 0-indexed integer arrays nums1 and nums2 of equal length. Every second, for all indices 0 <= i < nums1.length, value of nums1[i] is incremented by nums2[i]. After this is done, you can do the following operation: …
2762. Continuous Subarrays
#Problem You are given a 0-indexed integer array nums. A subarray of nums is called continuous if: Let i, i + 1, …, j be the indices in the subarray. Then, for each pair of indices i <= i₁, i₂ <= j, 0 <= |nums[i₁] - nums[i₂]| <= 2. Return …
3266. Final Array State After K Multiplication Operations II
#Problem You are given an integer array nums, an integer k, and an integer multiplier. You need to perform k operations on nums. In each operation: Find the minimum value x in nums. If there are multiple occurrences of the minimum value, …
2593. Find Score of an Array After Marking All Elements
#Problem You are given an array nums consisting of positive integers. Starting with score = 0, apply the following algorithm: Choose the smallest integer of the array that is not marked. If there is a tie, choose the one with the smallest …
3264. Final Array State After K Multiplication Operations I
#Problem You are given an integer array nums, an integer k, and an integer multiplier. You need to perform k operations on nums. In each operation: Find the minimum value x in nums. If there are multiple occurrences of the minimum value, …
2558. Take Gifts From the Richest Pile
#Problem You are given an integer array gifts denoting the number of gifts in various piles. Every second, you do the following: Choose the pile with the maximum number of gifts. If there is more than one pile with the maximum number of …
2931. Maximum Spending After Buying Items
#Problem You are given a 0-indexed m * n integer matrix values, representing the values of m * n different items in m different shops. Each shop has n items where the jᵗʰ item in the iᵗʰ shop has a value of values[i][j]. Additionally, the …
2699. Modify Graph Edge Weights
#Problem You are given an undirected weighted connected graph containing n nodes labeled from 0 to n - 1, and an integer array edges where edges[i] = [aᵢ, bᵢ, wᵢ] indicates that there is an edge between nodes aᵢ and bᵢ with weight wᵢ. Some …
2779. Maximum Beauty of an Array After Applying Operation
#Problem You are given a 0-indexed array nums and a non-negative integer k. In one operation, you can do the following: Choose an index i that hasn’t been chosen before from the range [0, nums.length - 1]. Replace nums[i] with any integer …