medium
50. Pow(x, n)
#Problem Implement pow(x, n), which calculates x raised to the power n (i.e., xⁿ). https://leetcode.com/problems/powx-n/ Example 1: Input: x = 2.00000, n = 10 Output: 1024.00000 Example 2: Input: x = 2.10000, n = 3 Output: 9.26100 Example …
227. Basic Calculator II
#Problem Given a string s which represents an expression, evaluate this expression and return its value. The integer division should truncate toward zero. You may assume that the given expression is always valid. All intermediate results …
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 …
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 …
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 …
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, …
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 …
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. …
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 …
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 …
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 …
2982. Find Longest Special Substring That Occurs Thrice II
跟 2981. Find Longest Special Substring That Occurs Thrice I 一模一样,只不过 s 的长度上限从 50 增加到 5 * 10⁵。 https://leetcode.com/problems/find-longest-special-substring-that-occurs-thrice-ii/ 直接用上次的代码没问题。
2981. Find Longest Special Substring That Occurs Thrice I
#Problem You are given a string s that consists of lowercase English letters. A string is called special if it is made up of only a single character. For example, the string "abc" is not special, whereas the strings "ddd", "zz", and "f" are …
935. Knight Dialer
#Problem The chess knight has a unique movement, it may move two squares vertically and one square horizontally, or two squares horizontally and one square vertically (with both forming the shape of an L). The possible movements of chess …
954. Array of Doubled Pairs
#Problem Given an integer array of even length arr, return true if it is possible to reorder arr such that arr[2 * i + 1] = 2 * arr[2 * i] for every 0 <= i < len(arr) / 2, or false otherwise. …
2. Add Two Numbers
#Problem 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 contains a single digit. Add the two numbers and return the sum as a linked list. You …
3152. Special Array II
#Problem An array is considered special if every pair of its adjacent elements contains two numbers with different parity. You are given an array of integer nums and a 2D integer matrix queries, where for queries[i] = [fromᵢ, toᵢ] your task …
2054. Two Best Non-Overlapping Events
#Problem You are given a 0-indexed 2D integer array of events where events[i] = [startTimeᵢ, endTimeᵢ, valueᵢ]. The iᵗʰ event starts at startTimeᵢ and ends at endTimeᵢ, and if you attend this event, you will receive a value of valueᵢ. You …
1760. Minimum Limit of Balls in a Bag
#Problem You are given an integer array nums where the iᵗʰ bag contains nums[i] balls. You are also given an integer maxOperations. You can perform the following operation at most maxOperations times: Take any bag of balls and divide it …
688. Knight Probability in Chessboard
#Problem On an n x n chessboard, a knight starts at the cell (row, column) and attempts to make exactly k moves. The rows and columns are 0-indexed, so the top-left cell is (0, 0), and the bottom-right cell is (n - 1, n - 1). A chess knight …
2554. Maximum Number of Integers to Choose From a Range I
#Problem You are given an integer array banned and two integers n and maxSum. You are choosing some number of integers following the below rules: The chosen integers have to be in the range [1, n]. Each integer can be chosen at most once. …
2337. Move Pieces to Obtain a String
#Problem You are given two strings start and target, both of length n. Each string consists only of the characters 'L', 'R', and '_' where: The characters 'L' and 'R' represent pieces, where a piece 'L' can move to the left only if there is …
3001. Minimum Moves to Capture The Queen
#Problem There is a 1-indexed 8 x 8 chessboard containing 3 pieces. You are given 6 integers a, b, c, d, e, and f where: (a, b) denotes the position of the white rook. (c, d) denotes the position of the white bishop. (e, f) denotes the …
2825. Make String a Subsequence Using Cyclic Increments
#Problem You are given two 0-indexed strings str1 and str2. In an operation, you select a set of indices in str1, and for each index i in the set, increment str1[i] to the next character cyclically. That is 'a' becomes 'b', 'b' becomes 'c', …