feat: update lc problems (#2506)

This commit is contained in:
Libin YANG 2024-03-26 09:30:20 +08:00 committed by GitHub
parent 9b70ced919
commit d5441b5c1e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
64 changed files with 1154 additions and 691 deletions

View File

@ -50,7 +50,7 @@
记 $m$ 表示字符串 $s$ 的长度,$n$ 表示字符串 $t$ 的长度。我们可以假定 $m$ 恒大于等于 $n$。
若 $m-n\gt1$,直接返回 false
若 $m-n \gt 1$,直接返回 false
否则,遍历 $s$ 和 $t$,若遇到 $s[i]$ 不等于 $t[i]$
@ -59,7 +59,7 @@
遍历结束,说明遍历过的 $s$ 跟 $t$ 所有字符相等,此时需要满足 $m=n+1$。
时间复杂度 $O(m)$,空间复杂度 $O(1)$。
时间复杂度 $O(m)$其中 $m$ 为字符串 $s$ 的长度。空间复杂度 $O(1)$。
<!-- tabs:start -->
@ -139,6 +139,24 @@ func isOneEditDistance(s string, t string) bool {
}
```
```ts
function isOneEditDistance(s: string, t: string): boolean {
const [m, n] = [s.length, t.length];
if (m < n) {
return isOneEditDistance(t, s);
}
if (m - n > 1) {
return false;
}
for (let i = 0; i < n; ++i) {
if (s[i] !== t[i]) {
return s.slice(i + 1) === t.slice(i + (m === n ? 1 : 0));
}
}
return m === n + 1;
}
```
<!-- tabs:end -->
<!-- end -->

View File

@ -43,7 +43,20 @@
## Solutions
### Solution 1
### Solution 1: Discuss Different Cases
Let $m$ represent the length of string $s$, and $n$ represent the length of string $t$. We can assume that $m$ is always greater than or equal to $n$.
If $m-n > 1$, return false directly;
Otherwise, iterate through $s$ and $t$, if $s[i]$ is not equal to $t[i]$:
- If $m \neq n$, compare $s[i+1:]$ with $t[i:]$, return true if they are equal, otherwise return false;
- If $m = n$, compare $s[i:]$ with $t[i:]$, return true if they are equal, otherwise return false.
If the iteration ends, it means that all the characters of $s$ and $t$ that have been iterated are equal, at this time it needs to satisfy $m=n+1$.
The time complexity is $O(m)$, where $m$ is the length of string $s$. The space complexity is $O(1)$.
<!-- tabs:start -->
@ -123,6 +136,24 @@ func isOneEditDistance(s string, t string) bool {
}
```
```ts
function isOneEditDistance(s: string, t: string): boolean {
const [m, n] = [s.length, t.length];
if (m < n) {
return isOneEditDistance(t, s);
}
if (m - n > 1) {
return false;
}
for (let i = 0; i < n; ++i) {
if (s[i] !== t[i]) {
return s.slice(i + 1) === t.slice(i + (m === n ? 1 : 0));
}
}
return m === n + 1;
}
```
<!-- tabs:end -->
<!-- end -->

View File

@ -0,0 +1,15 @@
function isOneEditDistance(s: string, t: string): boolean {
const [m, n] = [s.length, t.length];
if (m < n) {
return isOneEditDistance(t, s);
}
if (m - n > 1) {
return false;
}
for (let i = 0; i < n; ++i) {
if (s[i] !== t[i]) {
return s.slice(i + 1) === t.slice(i + (m === n ? 1 : 0));
}
}
return m === n + 1;
}

View File

@ -55,7 +55,7 @@ $$
遍历数组结束之后,每个非空的桶内的最小值和最大值都可以确定。按照桶的编号从小到大的顺序依次遍历每个桶,当前的桶的最小值和上一个非空的桶的最大值是排序后的相邻元素,计算两个相邻元素之差,并更新最大间距。遍历桶结束之后即可得到最大间距。
时间复杂度 $O(n)$,空间复杂度 $O(n)$。
时间复杂度 $O(n)$,空间复杂度 $O(n)$。其中 $n$ 是数组 $nums$ 的长度。
<!-- tabs:start -->

View File

@ -37,7 +37,20 @@
## Solutions
### Solution 1
### Solution 1: Discuss Different Cases
Let $m$ represent the length of string $s$, and $n$ represent the length of string $t$. We can assume that $m$ is always greater than or equal to $n$.
If $m-n > 1$, return false directly;
Otherwise, iterate through $s$ and $t$, if $s[i]$ is not equal to $t[i]$:
- If $m \neq n$, compare $s[i+1:]$ with $t[i:]$, return true if they are equal, otherwise return false;
- If $m = n$, compare $s[i:]$ with $t[i:]$, return true if they are equal, otherwise return false.
If the iteration ends, it means that all the characters of $s$ and $t$ that have been iterated are equal, at this time it needs to satisfy $m=n+1$.
The time complexity is $O(m)$, where $m$ is the length of string $s$. The space complexity is $O(1)$.
<!-- tabs:start -->

View File

@ -159,13 +159,16 @@ func compareVersion(version1 string, version2 string) int {
```ts
function compareVersion(version1: string, version2: string): number {
let v1 = version1.split('.'),
v2 = version2.split('.');
for (let i = 0; i < Math.max(v1.length, v2.length); i++) {
let c1 = Number(v1[i] || 0),
c2 = Number(v2[i] || 0);
if (c1 > c2) return 1;
if (c1 < c2) return -1;
const v1 = version1.split('.');
const v2 = version2.split('.');
for (let i = 0; i < Math.max(v1.length, v2.length); ++i) {
const [n1, n2] = [+v1[i] || 0, +v2[i] || 0];
if (n1 < n2) {
return -1;
}
if (n1 > n2) {
return 1;
}
}
return 0;
}

View File

@ -152,13 +152,16 @@ func compareVersion(version1 string, version2 string) int {
```ts
function compareVersion(version1: string, version2: string): number {
let v1 = version1.split('.'),
v2 = version2.split('.');
for (let i = 0; i < Math.max(v1.length, v2.length); i++) {
let c1 = Number(v1[i] || 0),
c2 = Number(v2[i] || 0);
if (c1 > c2) return 1;
if (c1 < c2) return -1;
const v1 = version1.split('.');
const v2 = version2.split('.');
for (let i = 0; i < Math.max(v1.length, v2.length); ++i) {
const [n1, n2] = [+v1[i] || 0, +v2[i] || 0];
if (n1 < n2) {
return -1;
}
if (n1 > n2) {
return 1;
}
}
return 0;
}

View File

@ -1,11 +1,14 @@
function compareVersion(version1: string, version2: string): number {
let v1 = version1.split('.'),
v2 = version2.split('.');
for (let i = 0; i < Math.max(v1.length, v2.length); i++) {
let c1 = Number(v1[i] || 0),
c2 = Number(v2[i] || 0);
if (c1 > c2) return 1;
if (c1 < c2) return -1;
const v1 = version1.split('.');
const v2 = version2.split('.');
for (let i = 0; i < Math.max(v1.length, v2.length); ++i) {
const [n1, n2] = [+v1[i] || 0, +v2[i] || 0];
if (n1 < n2) {
return -1;
}
if (n1 > n2) {
return 1;
}
}
return 0;
}

View File

@ -50,7 +50,21 @@
## 解法
### 方法一
### 方法一:数学 + 哈希表
我们首先判断 $numerator$ 是否为 $0$,如果是,则直接返回 `"0"`
接着我们判断 $numerator$ 和 $denominator$ 是否异号,如果是,则结果为负数,我们将结果的第一个字符设为 `"-"`
然后我们将 $numerator$ 和 $denominator$ 取绝对值,分别记为 $a$ 和 $b$。由于分子和分母的范围为 $[-2^{31}, 2^{31} - 1]$,直接取绝对值可能会溢出,因此我们将 $a$ 和 $b$ 都转换为长整型。
接着我们计算整数部分,即 $a$ 除以 $b$ 的整数部分,将其转换为字符串并添加到结果中。然后我们将 $a$ 取余 $b$,记为 $a$。
如果 $a$ 为 $0$,说明结果为整数,直接返回结果。
接着我们计算小数部分,我们使用哈希表 $d$ 记录每个余数对应的结果的长度。我们不断将 $a$ 乘以 $10$,然后将 $a$ 除以 $b$ 的整数部分添加到结果中,然后将 $a$ 取余 $b$,记为 $a$。如果 $a$ 为 $0$,说明结果为有限小数,直接返回结果。如果 $a$ 在哈希表中出现过,说明结果为循环小数,我们找到循环的起始位置,将结果插入括号中,然后返回结果。
时间复杂度 $O(l)$,空间复杂度 $O(l)$,其中 $l$ 为结果的长度,本题中 $l < 10^4$
<!-- tabs:start -->
@ -58,29 +72,28 @@
class Solution:
def fractionToDecimal(self, numerator: int, denominator: int) -> str:
if numerator == 0:
return '0'
res = []
return "0"
ans = []
neg = (numerator > 0) ^ (denominator > 0)
if neg:
res.append('-')
num, d = abs(numerator), abs(denominator)
res.append(str(num // d))
num %= d
if num == 0:
return ''.join(res)
res.append('.')
mp = {}
while num != 0:
mp[num] = len(res)
num *= 10
res.append(str(num // d))
num %= d
if num in mp:
idx = mp[num]
res.insert(idx, '(')
res.append(')')
ans.append("-")
a, b = abs(numerator), abs(denominator)
ans.append(str(a // b))
a %= b
if a == 0:
return "".join(ans)
ans.append(".")
d = {}
while a:
d[a] = len(ans)
a *= 10
ans.append(str(a // b))
a %= b
if a in d:
ans.insert(d[a], "(")
ans.append(")")
break
return ''.join(res)
return "".join(ans)
```
```java
@ -92,23 +105,21 @@ class Solution {
StringBuilder sb = new StringBuilder();
boolean neg = (numerator > 0) ^ (denominator > 0);
sb.append(neg ? "-" : "");
long num = Math.abs((long) numerator);
long d = Math.abs((long) denominator);
sb.append(num / d);
num %= d;
if (num == 0) {
long a = Math.abs((long) numerator), b = Math.abs((long) denominator);
sb.append(a / b);
a %= b;
if (a == 0) {
return sb.toString();
}
sb.append(".");
Map<Long, Integer> mp = new HashMap<>();
while (num != 0) {
mp.put(num, sb.length());
num *= 10;
sb.append(num / d);
num %= d;
if (mp.containsKey(num)) {
int idx = mp.get(num);
sb.insert(idx, "(");
Map<Long, Integer> d = new HashMap<>();
while (a != 0) {
d.put(a, sb.length());
a *= 10;
sb.append(a / b);
a %= b;
if (d.containsKey(a)) {
sb.insert(d.get(a), "(");
sb.append(")");
break;
}
@ -119,35 +130,37 @@ class Solution {
```
```cpp
using LL = long long;
class Solution {
public:
string fractionToDecimal(int numerator, int denominator) {
if (numerator == 0) return "0";
string res = "";
if (numerator == 0) {
return "0";
}
string ans;
bool neg = (numerator > 0) ^ (denominator > 0);
if (neg) res += "-";
LL num = abs(numerator);
LL d = abs(denominator);
res += to_string(num / d);
num %= d;
if (num == 0) return res;
res += ".";
unordered_map<LL, int> mp;
while (num) {
mp[num] = res.size();
num *= 10;
res += to_string(num / d);
num %= d;
if (mp.count(num)) {
int idx = mp[num];
res.insert(idx, "(");
res += ")";
if (neg) {
ans += "-";
}
long long a = abs(1LL * numerator), b = abs(1LL * denominator);
ans += to_string(a / b);
a %= b;
if (a == 0) {
return ans;
}
ans += ".";
unordered_map<long long, int> d;
while (a) {
d[a] = ans.size();
a *= 10;
ans += to_string(a / b);
a %= b;
if (d.contains(a)) {
ans.insert(d[a], "(");
ans += ")";
break;
}
}
return res;
return ans;
}
};
```
@ -157,37 +170,35 @@ func fractionToDecimal(numerator int, denominator int) string {
if numerator == 0 {
return "0"
}
res := []byte{}
neg := numerator*denominator < 0
if neg {
res = append(res, '-')
ans := ""
if (numerator > 0) != (denominator > 0) {
ans += "-"
}
num := abs(numerator)
d := abs(denominator)
res = append(res, strconv.Itoa(num/d)...)
num %= d
if num == 0 {
return string(res)
a := int64(numerator)
b := int64(denominator)
a = abs(a)
b = abs(b)
ans += strconv.FormatInt(a/b, 10)
a %= b
if a == 0 {
return ans
}
mp := make(map[int]int)
res = append(res, '.')
for num != 0 {
mp[num] = len(res)
num *= 10
res = append(res, strconv.Itoa(num/d)...)
num %= d
if mp[num] > 0 {
idx := mp[num]
res = append(res[:idx], append([]byte{'('}, res[idx:]...)...)
res = append(res, ')')
ans += "."
d := make(map[int64]int)
for a != 0 {
if pos, ok := d[a]; ok {
ans = ans[:pos] + "(" + ans[pos:] + ")"
break
}
d[a] = len(ans)
a *= 10
ans += strconv.FormatInt(a/b, 10)
a %= b
}
return string(res)
return ans
}
func abs(x int) int {
func abs(x int64) int64 {
if x < 0 {
return -x
}
@ -195,59 +206,64 @@ func abs(x int) int {
}
```
```ts
function fractionToDecimal(numerator: number, denominator: number): string {
if (numerator === 0) {
return '0';
}
const sb: string[] = [];
const neg: boolean = numerator > 0 !== denominator > 0;
sb.push(neg ? '-' : '');
let a: number = Math.abs(numerator),
b: number = Math.abs(denominator);
sb.push(Math.floor(a / b).toString());
a %= b;
if (a === 0) {
return sb.join('');
}
sb.push('.');
const d: Map<number, number> = new Map();
while (a !== 0) {
d.set(a, sb.length);
a *= 10;
sb.push(Math.floor(a / b).toString());
a %= b;
if (d.has(a)) {
sb.splice(d.get(a)!, 0, '(');
sb.push(')');
break;
}
}
return sb.join('');
}
```
```cs
// https://leetcode.com/problems/fraction-to-recurring-decimal/
using System.Collections.Generic;
using System.Text;
public partial class Solution
{
public string FractionToDecimal(int numerator, int denominator)
{
var n = (long)numerator;
var d = (long)denominator;
var sb = new StringBuilder();
if (n < 0)
{
n = -n;
if (d < 0)
{
d = -d;
}
else
{
sb.Append('-');
}
public class Solution {
public string FractionToDecimal(int numerator, int denominator) {
if (numerator == 0) {
return "0";
}
else if (n > 0 && d < 0)
{
d = -d;
sb.Append('-');
StringBuilder sb = new StringBuilder();
bool neg = (numerator > 0) ^ (denominator > 0);
sb.Append(neg ? "-" : "");
long a = Math.Abs((long)numerator), b = Math.Abs((long)denominator);
sb.Append(a / b);
a %= b;
if (a == 0) {
return sb.ToString();
}
sb.Append(n / d);
n = n % d;
if (n != 0)
{
sb.Append('.');
var dict = new Dictionary<long, int>();
while (n != 0)
{
int index;
if (dict.TryGetValue(n, out index))
{
sb.Insert(index, '(');
sb.Append(')');
break;
}
else
{
dict.Add(n, sb.Length);
n *= 10;
sb.Append(n / d);
n %= d;
}
sb.Append(".");
Dictionary<long, int> d = new Dictionary<long, int>();
while (a != 0) {
d[a] = sb.Length;
a *= 10;
sb.Append(a / b);
a %= b;
if (d.ContainsKey(a)) {
sb.Insert(d[a], "(");
sb.Append(")");
break;
}
}
return sb.ToString();

View File

@ -46,7 +46,21 @@
## Solutions
### Solution 1
### Solution 1: Mathematics + Hash Table
First, we check if the $numerator$ is $0$. If it is, we return `"0"` directly.
Next, we check if the $numerator$ and $denominator$ have different signs. If they do, the result is negative, and we set the first character of the result to `"-"`.
Then we take the absolute values of the $numerator$ and $denominator$, denoted as $a$ and $b$. Since the range of the numerator and denominator is $[-2^{31}, 2^{31} - 1]$, taking the absolute value directly may cause overflow, so we convert both $a$ and $b$ to long integers.
Next, we calculate the integer part, which is the integer part of $a$ divided by $b$, convert it to a string, and add it to the result. Then we take the remainder of $a$ divided by $b$, denoted as $a$.
If $a$ is $0$, it means the result is an integer, and we return the result directly.
Next, we calculate the decimal part. We use a hash table $d$ to record the length of the result corresponding to each remainder. We continuously multiply $a$ by $10$, then add the integer part of $a$ divided by $b$ to the result, then take the remainder of $a$ divided by $b$, denoted as $a$. If $a$ is $0$, it means the result is a finite decimal, and we return the result directly. If $a$ has appeared in the hash table, it means the result is a recurring decimal. We find the starting position of the cycle, insert the result into parentheses, and then return the result.
The time complexity is $O(l)$, and the space complexity is $O(l)$, where $l$ is the length of the result. In this problem, $l < 10^4$.
<!-- tabs:start -->
@ -54,29 +68,28 @@
class Solution:
def fractionToDecimal(self, numerator: int, denominator: int) -> str:
if numerator == 0:
return '0'
res = []
return "0"
ans = []
neg = (numerator > 0) ^ (denominator > 0)
if neg:
res.append('-')
num, d = abs(numerator), abs(denominator)
res.append(str(num // d))
num %= d
if num == 0:
return ''.join(res)
res.append('.')
mp = {}
while num != 0:
mp[num] = len(res)
num *= 10
res.append(str(num // d))
num %= d
if num in mp:
idx = mp[num]
res.insert(idx, '(')
res.append(')')
ans.append("-")
a, b = abs(numerator), abs(denominator)
ans.append(str(a // b))
a %= b
if a == 0:
return "".join(ans)
ans.append(".")
d = {}
while a:
d[a] = len(ans)
a *= 10
ans.append(str(a // b))
a %= b
if a in d:
ans.insert(d[a], "(")
ans.append(")")
break
return ''.join(res)
return "".join(ans)
```
```java
@ -88,23 +101,21 @@ class Solution {
StringBuilder sb = new StringBuilder();
boolean neg = (numerator > 0) ^ (denominator > 0);
sb.append(neg ? "-" : "");
long num = Math.abs((long) numerator);
long d = Math.abs((long) denominator);
sb.append(num / d);
num %= d;
if (num == 0) {
long a = Math.abs((long) numerator), b = Math.abs((long) denominator);
sb.append(a / b);
a %= b;
if (a == 0) {
return sb.toString();
}
sb.append(".");
Map<Long, Integer> mp = new HashMap<>();
while (num != 0) {
mp.put(num, sb.length());
num *= 10;
sb.append(num / d);
num %= d;
if (mp.containsKey(num)) {
int idx = mp.get(num);
sb.insert(idx, "(");
Map<Long, Integer> d = new HashMap<>();
while (a != 0) {
d.put(a, sb.length());
a *= 10;
sb.append(a / b);
a %= b;
if (d.containsKey(a)) {
sb.insert(d.get(a), "(");
sb.append(")");
break;
}
@ -115,35 +126,37 @@ class Solution {
```
```cpp
using LL = long long;
class Solution {
public:
string fractionToDecimal(int numerator, int denominator) {
if (numerator == 0) return "0";
string res = "";
if (numerator == 0) {
return "0";
}
string ans;
bool neg = (numerator > 0) ^ (denominator > 0);
if (neg) res += "-";
LL num = abs(numerator);
LL d = abs(denominator);
res += to_string(num / d);
num %= d;
if (num == 0) return res;
res += ".";
unordered_map<LL, int> mp;
while (num) {
mp[num] = res.size();
num *= 10;
res += to_string(num / d);
num %= d;
if (mp.count(num)) {
int idx = mp[num];
res.insert(idx, "(");
res += ")";
if (neg) {
ans += "-";
}
long long a = abs(1LL * numerator), b = abs(1LL * denominator);
ans += to_string(a / b);
a %= b;
if (a == 0) {
return ans;
}
ans += ".";
unordered_map<long long, int> d;
while (a) {
d[a] = ans.size();
a *= 10;
ans += to_string(a / b);
a %= b;
if (d.contains(a)) {
ans.insert(d[a], "(");
ans += ")";
break;
}
}
return res;
return ans;
}
};
```
@ -153,37 +166,35 @@ func fractionToDecimal(numerator int, denominator int) string {
if numerator == 0 {
return "0"
}
res := []byte{}
neg := numerator*denominator < 0
if neg {
res = append(res, '-')
ans := ""
if (numerator > 0) != (denominator > 0) {
ans += "-"
}
num := abs(numerator)
d := abs(denominator)
res = append(res, strconv.Itoa(num/d)...)
num %= d
if num == 0 {
return string(res)
a := int64(numerator)
b := int64(denominator)
a = abs(a)
b = abs(b)
ans += strconv.FormatInt(a/b, 10)
a %= b
if a == 0 {
return ans
}
mp := make(map[int]int)
res = append(res, '.')
for num != 0 {
mp[num] = len(res)
num *= 10
res = append(res, strconv.Itoa(num/d)...)
num %= d
if mp[num] > 0 {
idx := mp[num]
res = append(res[:idx], append([]byte{'('}, res[idx:]...)...)
res = append(res, ')')
ans += "."
d := make(map[int64]int)
for a != 0 {
if pos, ok := d[a]; ok {
ans = ans[:pos] + "(" + ans[pos:] + ")"
break
}
d[a] = len(ans)
a *= 10
ans += strconv.FormatInt(a/b, 10)
a %= b
}
return string(res)
return ans
}
func abs(x int) int {
func abs(x int64) int64 {
if x < 0 {
return -x
}
@ -191,59 +202,64 @@ func abs(x int) int {
}
```
```ts
function fractionToDecimal(numerator: number, denominator: number): string {
if (numerator === 0) {
return '0';
}
const sb: string[] = [];
const neg: boolean = numerator > 0 !== denominator > 0;
sb.push(neg ? '-' : '');
let a: number = Math.abs(numerator),
b: number = Math.abs(denominator);
sb.push(Math.floor(a / b).toString());
a %= b;
if (a === 0) {
return sb.join('');
}
sb.push('.');
const d: Map<number, number> = new Map();
while (a !== 0) {
d.set(a, sb.length);
a *= 10;
sb.push(Math.floor(a / b).toString());
a %= b;
if (d.has(a)) {
sb.splice(d.get(a)!, 0, '(');
sb.push(')');
break;
}
}
return sb.join('');
}
```
```cs
// https://leetcode.com/problems/fraction-to-recurring-decimal/
using System.Collections.Generic;
using System.Text;
public partial class Solution
{
public string FractionToDecimal(int numerator, int denominator)
{
var n = (long)numerator;
var d = (long)denominator;
var sb = new StringBuilder();
if (n < 0)
{
n = -n;
if (d < 0)
{
d = -d;
}
else
{
sb.Append('-');
}
public class Solution {
public string FractionToDecimal(int numerator, int denominator) {
if (numerator == 0) {
return "0";
}
else if (n > 0 && d < 0)
{
d = -d;
sb.Append('-');
StringBuilder sb = new StringBuilder();
bool neg = (numerator > 0) ^ (denominator > 0);
sb.Append(neg ? "-" : "");
long a = Math.Abs((long)numerator), b = Math.Abs((long)denominator);
sb.Append(a / b);
a %= b;
if (a == 0) {
return sb.ToString();
}
sb.Append(n / d);
n = n % d;
if (n != 0)
{
sb.Append('.');
var dict = new Dictionary<long, int>();
while (n != 0)
{
int index;
if (dict.TryGetValue(n, out index))
{
sb.Insert(index, '(');
sb.Append(')');
break;
}
else
{
dict.Add(n, sb.Length);
n *= 10;
sb.Append(n / d);
n %= d;
}
sb.Append(".");
Dictionary<long, int> d = new Dictionary<long, int>();
while (a != 0) {
d[a] = sb.Length;
a *= 10;
sb.Append(a / b);
a %= b;
if (d.ContainsKey(a)) {
sb.Insert(d[a], "(");
sb.Append(")");
break;
}
}
return sb.ToString();

View File

@ -1,31 +1,33 @@
using LL = long long;
class Solution {
public:
string fractionToDecimal(int numerator, int denominator) {
if (numerator == 0) return "0";
string res = "";
if (numerator == 0) {
return "0";
}
string ans;
bool neg = (numerator > 0) ^ (denominator > 0);
if (neg) res += "-";
LL num = abs(numerator);
LL d = abs(denominator);
res += to_string(num / d);
num %= d;
if (num == 0) return res;
res += ".";
unordered_map<LL, int> mp;
while (num) {
mp[num] = res.size();
num *= 10;
res += to_string(num / d);
num %= d;
if (mp.count(num)) {
int idx = mp[num];
res.insert(idx, "(");
res += ")";
if (neg) {
ans += "-";
}
long long a = abs(1LL * numerator), b = abs(1LL * denominator);
ans += to_string(a / b);
a %= b;
if (a == 0) {
return ans;
}
ans += ".";
unordered_map<long long, int> d;
while (a) {
d[a] = ans.size();
a *= 10;
ans += to_string(a / b);
a %= b;
if (d.contains(a)) {
ans.insert(d[a], "(");
ans += ")";
break;
}
}
return res;
return ans;
}
};

View File

@ -1,55 +1,28 @@
// https://leetcode.com/problems/fraction-to-recurring-decimal/
using System.Collections.Generic;
using System.Text;
public partial class Solution
{
public string FractionToDecimal(int numerator, int denominator)
{
var n = (long)numerator;
var d = (long)denominator;
var sb = new StringBuilder();
if (n < 0)
{
n = -n;
if (d < 0)
{
d = -d;
}
else
{
sb.Append('-');
}
public class Solution {
public string FractionToDecimal(int numerator, int denominator) {
if (numerator == 0) {
return "0";
}
else if (n > 0 && d < 0)
{
d = -d;
sb.Append('-');
StringBuilder sb = new StringBuilder();
bool neg = (numerator > 0) ^ (denominator > 0);
sb.Append(neg ? "-" : "");
long a = Math.Abs((long)numerator), b = Math.Abs((long)denominator);
sb.Append(a / b);
a %= b;
if (a == 0) {
return sb.ToString();
}
sb.Append(n / d);
n = n % d;
if (n != 0)
{
sb.Append('.');
var dict = new Dictionary<long, int>();
while (n != 0)
{
int index;
if (dict.TryGetValue(n, out index))
{
sb.Insert(index, '(');
sb.Append(')');
break;
}
else
{
dict.Add(n, sb.Length);
n *= 10;
sb.Append(n / d);
n %= d;
}
sb.Append(".");
Dictionary<long, int> d = new Dictionary<long, int>();
while (a != 0) {
d[a] = sb.Length;
a *= 10;
sb.Append(a / b);
a %= b;
if (d.ContainsKey(a)) {
sb.Insert(d[a], "(");
sb.Append(")");
break;
}
}
return sb.ToString();

View File

@ -2,37 +2,35 @@ func fractionToDecimal(numerator int, denominator int) string {
if numerator == 0 {
return "0"
}
res := []byte{}
neg := numerator*denominator < 0
if neg {
res = append(res, '-')
ans := ""
if (numerator > 0) != (denominator > 0) {
ans += "-"
}
num := abs(numerator)
d := abs(denominator)
res = append(res, strconv.Itoa(num/d)...)
num %= d
if num == 0 {
return string(res)
a := int64(numerator)
b := int64(denominator)
a = abs(a)
b = abs(b)
ans += strconv.FormatInt(a/b, 10)
a %= b
if a == 0 {
return ans
}
mp := make(map[int]int)
res = append(res, '.')
for num != 0 {
mp[num] = len(res)
num *= 10
res = append(res, strconv.Itoa(num/d)...)
num %= d
if mp[num] > 0 {
idx := mp[num]
res = append(res[:idx], append([]byte{'('}, res[idx:]...)...)
res = append(res, ')')
ans += "."
d := make(map[int64]int)
for a != 0 {
if pos, ok := d[a]; ok {
ans = ans[:pos] + "(" + ans[pos:] + ")"
break
}
d[a] = len(ans)
a *= 10
ans += strconv.FormatInt(a/b, 10)
a %= b
}
return string(res)
return ans
}
func abs(x int) int {
func abs(x int64) int64 {
if x < 0 {
return -x
}

View File

@ -6,23 +6,21 @@ class Solution {
StringBuilder sb = new StringBuilder();
boolean neg = (numerator > 0) ^ (denominator > 0);
sb.append(neg ? "-" : "");
long num = Math.abs((long) numerator);
long d = Math.abs((long) denominator);
sb.append(num / d);
num %= d;
if (num == 0) {
long a = Math.abs((long) numerator), b = Math.abs((long) denominator);
sb.append(a / b);
a %= b;
if (a == 0) {
return sb.toString();
}
sb.append(".");
Map<Long, Integer> mp = new HashMap<>();
while (num != 0) {
mp.put(num, sb.length());
num *= 10;
sb.append(num / d);
num %= d;
if (mp.containsKey(num)) {
int idx = mp.get(num);
sb.insert(idx, "(");
Map<Long, Integer> d = new HashMap<>();
while (a != 0) {
d.put(a, sb.length());
a *= 10;
sb.append(a / b);
a %= b;
if (d.containsKey(a)) {
sb.insert(d.get(a), "(");
sb.append(")");
break;
}

View File

@ -1,26 +1,25 @@
class Solution:
def fractionToDecimal(self, numerator: int, denominator: int) -> str:
if numerator == 0:
return '0'
res = []
return "0"
ans = []
neg = (numerator > 0) ^ (denominator > 0)
if neg:
res.append('-')
num, d = abs(numerator), abs(denominator)
res.append(str(num // d))
num %= d
if num == 0:
return ''.join(res)
res.append('.')
mp = {}
while num != 0:
mp[num] = len(res)
num *= 10
res.append(str(num // d))
num %= d
if num in mp:
idx = mp[num]
res.insert(idx, '(')
res.append(')')
ans.append("-")
a, b = abs(numerator), abs(denominator)
ans.append(str(a // b))
a %= b
if a == 0:
return "".join(ans)
ans.append(".")
d = {}
while a:
d[a] = len(ans)
a *= 10
ans.append(str(a // b))
a %= b
if a in d:
ans.insert(d[a], "(")
ans.append(")")
break
return ''.join(res)
return "".join(ans)

View File

@ -0,0 +1,29 @@
function fractionToDecimal(numerator: number, denominator: number): string {
if (numerator === 0) {
return '0';
}
const sb: string[] = [];
const neg: boolean = numerator > 0 !== denominator > 0;
sb.push(neg ? '-' : '');
let a: number = Math.abs(numerator),
b: number = Math.abs(denominator);
sb.push(Math.floor(a / b).toString());
a %= b;
if (a === 0) {
return sb.join('');
}
sb.push('.');
const d: Map<number, number> = new Map();
while (a !== 0) {
d.set(a, sb.length);
a *= 10;
sb.push(Math.floor(a / b).toString());
a %= b;
if (d.has(a)) {
sb.splice(d.get(a)!, 0, '(');
sb.push(')');
break;
}
}
return sb.join('');
}

View File

@ -6,39 +6,44 @@
## Description
<p>Write a function that takes&nbsp;the binary representation of an unsigned integer and returns the number of &#39;1&#39; bits it has (also known as the <a href="http://en.wikipedia.org/wiki/Hamming_weight" target="_blank">Hamming weight</a>).</p>
<p><strong>Note:</strong></p>
<ul>
<li>Note that in some languages, such as Java, there is no unsigned integer type. In this case, the input will be given as a signed integer type. It should not affect your implementation, as the integer&#39;s internal binary representation is the same, whether it is signed or unsigned.</li>
<li>In Java, the compiler represents the signed integers using <a href="https://en.wikipedia.org/wiki/Two%27s_complement" target="_blank">2&#39;s complement notation</a>. Therefore, in <strong class="example">Example 3</strong>, the input represents the signed integer. <code>-3</code>.</li>
</ul>
<p>Write a function that takes the binary representation of a positive integer and returns the number of <span data-keyword="set-bit">set bits</span> it has (also known as the <a href="http://en.wikipedia.org/wiki/Hamming_weight" target="_blank">Hamming weight</a>).</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> n = 00000000000000000000000000001011
<strong>Output:</strong> 3
<strong>Explanation:</strong> The input binary string <strong>00000000000000000000000000001011</strong> has a total of three &#39;1&#39; bits.
</pre>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">n = 11</span></p>
<p><strong>Output:</strong> <span class="example-io">3</span></p>
<p><strong>Explanation:</strong></p>
<p>The input binary string <strong>1011</strong> has a total of three set bits.</p>
</div>
<p><strong class="example">Example 2:</strong></p>
<pre>
<strong>Input:</strong> n = 00000000000000000000000010000000
<strong>Output:</strong> 1
<strong>Explanation:</strong> The input binary string <strong>00000000000000000000000010000000</strong> has a total of one &#39;1&#39; bit.
</pre>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">n = 128</span></p>
<p><strong>Output:</strong> <span class="example-io">1</span></p>
<p><strong>Explanation:</strong></p>
<p>The input binary string <strong>10000000</strong> has a total of one set bit.</p>
</div>
<p><strong class="example">Example 3:</strong></p>
<pre>
<strong>Input:</strong> n = 11111111111111111111111111111101
<strong>Output:</strong> 31
<strong>Explanation:</strong> The input binary string <strong>11111111111111111111111111111101</strong> has a total of thirty one &#39;1&#39; bits.
</pre>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">n = 2147483645</span></p>
<p><strong>Output:</strong> <span class="example-io">30</span></p>
<p><strong>Explanation:</strong></p>
<p>The input binary string <strong>1111111111111111111111111111101</strong> has a total of thirty set bits.</p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

View File

@ -2,7 +2,7 @@
[English Version](/solution/0300-0399/0321.Create%20Maximum%20Number/README_EN.md)
<!-- tags:栈,贪心,单调栈 -->
<!-- tags:栈,贪心,数组,双指针,单调栈 -->
## 题目描述

View File

@ -2,7 +2,7 @@
[中文文档](/solution/0300-0399/0321.Create%20Maximum%20Number/README.md)
<!-- tags:Stack,Greedy,Monotonic Stack -->
<!-- tags:Stack,Greedy,Array,Two Pointers,Monotonic Stack -->
## Description

View File

@ -8,7 +8,7 @@
<!-- 这里写题目描述 -->
<p>给定两个数组&nbsp;<code>nums1</code>&nbsp;&nbsp;<code>nums2</code> ,返回 <em>它们的交集</em>&nbsp;。输出结果中的每个元素一定是 <strong>唯一</strong> 的。我们可以 <strong>不考虑输出结果的顺序</strong></p>
<p>给定两个数组&nbsp;<code>nums1</code>&nbsp;&nbsp;<code>nums2</code> ,返回 <em>它们的 <span data-keyword="array-intersection">交集</span></em>&nbsp;。输出结果中的每个元素一定是 <strong>唯一</strong> 的。我们可以 <strong>不考虑输出结果的顺序</strong></p>
<p>&nbsp;</p>

View File

@ -6,7 +6,7 @@
## Description
<p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, return <em>an array of their intersection</em>. Each element in the result must be <strong>unique</strong> and you may return the result in <strong>any order</strong>.</p>
<p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, return <em>an array of their <span data-keyword="array-intersection">intersection</span></em>. Each element in the result must be <strong>unique</strong> and you may return the result in <strong>any order</strong>.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

View File

@ -2,7 +2,7 @@
[English Version](/solution/0800-0899/0840.Magic%20Squares%20In%20Grid/README_EN.md)
<!-- tags:数组,数学,矩阵 -->
<!-- tags:数组,哈希表,数学,矩阵 -->
## 题目描述

View File

@ -2,7 +2,7 @@
[中文文档](/solution/0800-0899/0840.Magic%20Squares%20In%20Grid/README.md)
<!-- tags:Array,Math,Matrix -->
<!-- tags:Array,Hash Table,Math,Matrix -->
## Description

View File

@ -54,6 +54,34 @@ Employees table:
<strong>Explanation:</strong> Hercy has 2 people report directly to him, Alice and Bob. Their average age is (41+36)/2 = 38.5, which is 39 after rounding it to the nearest integer.
</pre>
<p><strong class="example">Example 2:</strong></p>
<pre>
<strong>Input:</strong>
Employees table:
+-------------+---------+------------+-----+
| employee_id | name &nbsp; &nbsp;| reports_to | age |
|-------------|---------|------------|-----|
| 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | Michael | null &nbsp; &nbsp; &nbsp; | 45 &nbsp;|
| 2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | Alice &nbsp; | 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| 38 &nbsp;|
| 3 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | Bob &nbsp; &nbsp; | 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| 42 &nbsp;|
| 4 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | Charlie | 2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| 34 &nbsp;|
| 5 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | David &nbsp; | 2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| 40 &nbsp;|
| 6 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | Eve &nbsp; &nbsp; | 3 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| 37 &nbsp;|
| 7 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | Frank &nbsp; | null &nbsp; &nbsp; &nbsp; | 50 &nbsp;|
| 8 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | Grace &nbsp; | null &nbsp; &nbsp; &nbsp; | 48 &nbsp;|
+-------------+---------+------------+-----+
<strong>Output:</strong>
+-------------+---------+---------------+-------------+
| employee_id | name &nbsp; &nbsp;| reports_count | average_age |
| ----------- | ------- | ------------- | ----------- |
| 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | Michael | 2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | 40 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|
| 2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | Alice &nbsp; | 2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | 37 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|
| 3 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | Bob &nbsp; &nbsp; | 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | 37 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|
+-------------+---------+---------------+-------------+
</pre>
## Solutions
### Solution 1: Self-Join + Grouping

View File

@ -48,7 +48,7 @@
<p><strong>Constraints:</strong></p>
<ul>
<li><code>evnet1.length == event2.length == 2.</code></li>
<li>event1<code>.length == </code>event2<code>.length == 2.</code></li>
<li><code>event1[i].length == event2[i].length == 5</code></li>
<li><code>startTime<sub>1</sub> &lt;= endTime<sub>1</sub></code></li>
<li><code>startTime<sub>2</sub> &lt;= endTime<sub>2</sub></code></li>

View File

@ -2,7 +2,7 @@
[English Version](/solution/2600-2699/2617.Minimum%20Number%20of%20Visited%20Cells%20in%20a%20Grid/README_EN.md)
<!-- tags:栈,并查集,树状数组,线段树,数组,二分查找,动态规划 -->
<!-- tags:栈,广度优先搜索,并查集,数组,动态规划,矩阵,单调栈,堆(优先队列) -->
## 题目描述

View File

@ -2,7 +2,7 @@
[中文文档](/solution/2600-2699/2617.Minimum%20Number%20of%20Visited%20Cells%20in%20a%20Grid/README.md)
<!-- tags:Stack,Union Find,Binary Indexed Tree,Segment Tree,Array,Binary Search,Dynamic Programming -->
<!-- tags:Stack,Breadth-First Search,Union Find,Array,Dynamic Programming,Matrix,Monotonic Stack,Heap (Priority Queue) -->
## Description

View File

@ -6,35 +6,42 @@
## Description
<p>You have <code>n</code> processors each having <code>4</code> cores and <code>n * 4</code> tasks that need to be executed such that each core should perform only <strong>one</strong> task.</p>
<p>You have a certain number of processors, each having 4 cores. The number of tasks to be executed is four times the number of processors. Each task must be assigned to a unique core, and each core can only be used once.</p>
<p>Given a <strong>0-indexed</strong> integer array <code>processorTime</code> representing the time at which each processor becomes available for the first time and a <strong>0-indexed </strong>integer array <code>tasks</code> representing the time it takes to execute each task, return <em>the <strong>minimum</strong> time when all of the tasks have been executed by the processors.</em></p>
<p><strong>Note: </strong>Each core executes the task independently of the others.</p>
<p>You are given an array <code>processorTime</code> representing the time each processor becomes available and an array <code>tasks</code> representing how long each task takes to complete. Return the&nbsp;<em>minimum</em> time needed to complete all tasks.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> processorTime = [8,10], tasks = [2,2,3,1,8,7,4,5]
<strong>Output:</strong> 16
<strong>Explanation:</strong>
It&#39;s optimal to assign the tasks at indexes 4, 5, 6, 7 to the first processor which becomes available at time = 8, and the tasks at indexes 0, 1, 2, 3 to the second processor which becomes available at time = 10.
Time taken by the first processor to finish execution of all tasks = max(8 + 8, 8 + 7, 8 + 4, 8 + 5) = 16.
Time taken by the second processor to finish execution of all tasks = max(10 + 2, 10 + 2, 10 + 3, 10 + 1) = 13.
Hence, it can be shown that the minimum time taken to execute all the tasks is 16.</pre>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">processorTime = [8,10], tasks = [2,2,3,1,8,7,4,5]</span></p>
<p><strong>Output:</strong> <span class="example-io">16</span></p>
<p><strong>Explanation:</strong></p>
<p>Assign the tasks at indices 4, 5, 6, 7 to the first processor which becomes available at <code>time = 8</code>, and the tasks at indices 0, 1, 2, 3 to the second processor which becomes available at <code>time = 10</code>.&nbsp;</p>
<p>The time taken by the first processor to finish the execution of all tasks is&nbsp;<code>max(8 + 8, 8 + 7, 8 + 4, 8 + 5) = 16</code>.</p>
<p>The time taken by the second processor to finish the execution of all tasks is&nbsp;<code>max(10 + 2, 10 + 2, 10 + 3, 10 + 1) = 13</code>.</p>
</div>
<p><strong class="example">Example 2:</strong></p>
<pre>
<strong>Input:</strong> processorTime = [10,20], tasks = [2,3,1,2,5,8,4,3]
<strong>Output:</strong> 23
<strong>Explanation:</strong>
It&#39;s optimal to assign the tasks at indexes 1, 4, 5, 6 to the first processor which becomes available at time = 10, and the tasks at indexes 0, 2, 3, 7 to the second processor which becomes available at time = 20.
Time taken by the first processor to finish execution of all tasks = max(10 + 3, 10 + 5, 10 + 8, 10 + 4) = 18.
Time taken by the second processor to finish execution of all tasks = max(20 + 2, 20 + 1, 20 + 2, 20 + 3) = 23.
Hence, it can be shown that the minimum time taken to execute all the tasks is 23.
</pre>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">processorTime = [10,20], tasks = [2,3,1,2,5,8,4,3]</span></p>
<p><strong>Output:</strong> <span class="example-io">23</span></p>
<p><strong>Explanation:</strong></p>
<p>Assign the tasks at indices 1, 4, 5, 6 to the first processor and the others to the second processor.</p>
<p>The time taken by the first processor to finish the execution of all tasks is <code>max(10 + 3, 10 + 5, 10 + 8, 10 + 4) = 18</code>.</p>
<p>The time taken by the second processor to finish the execution of all tasks is <code>max(20 + 2, 20 + 1, 20 + 2, 20 + 3) = 23</code>.</p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

View File

@ -8,9 +8,7 @@
<!-- 这里写题目描述 -->
<p>给你一个整数数组&nbsp;<code>nums</code>&nbsp;,其中&nbsp;<code>nums[i]</code>&nbsp;要么是一个正整数,要么是&nbsp;<code>-1</code>&nbsp;</p>
<p>我们需要为每个 <code>-1</code> 找到相应的正整数,我们称之为最后访问的整数。</p>
<p>给你一个整数数组&nbsp;<code>nums</code>&nbsp;,其中&nbsp;<code>nums[i]</code>&nbsp;要么是一个正整数,要么是&nbsp;<code>-1</code>&nbsp;。我们需要为每个 <code>-1</code> 找到相应的正整数,我们称之为最后访问的整数。</p>
<p>为了达到这个目标,定义两个空数组:<code>seen</code>&nbsp;&nbsp;<code>ans</code></p>

View File

@ -6,9 +6,7 @@
## Description
<p>Given an integer array <code>nums</code> where <code>nums[i]</code> is either a positive integer or <code>-1</code>.</p>
<p>We need to find for each <code>-1</code> the respective positive integer, which we call the last visited integer.</p>
<p>Given an integer array <code>nums</code> where <code>nums[i]</code> is either a positive integer or <code>-1</code>. We need to find for each <code>-1</code> the respective positive integer, which we call the last visited integer.</p>
<p>To achieve this goal, let&#39;s define two empty arrays: <code>seen</code> and <code>ans</code>.</p>
@ -24,27 +22,19 @@
</li>
</ul>
<p>Return <em>the array </em><code>ans</code>.</p>
<p>Return the array<em> </em><code>ans</code>.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block" style="
border-color: var(--border-tertiary);
border-left-width: 2px;
color: var(--text-secondary);
font-size: .875rem;
line-height: 1.25rem;
margin-bottom: 1rem;
margin-top: 1rem;
overflow: visible;
padding-left: 1rem;
">
<p><strong>Input:</strong> <code>nums = [1,2,-1,-1,-1]</code></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">nums = [1,2,-1,-1,-1]</span></p>
<p><strong>Output:</strong> <code>[2,1,-1]</code></p>
<p><strong>Output:</strong> <span class="example-io">[2,1,-1]</span></p>
<p><strong>Explanation:</strong> Start with <code>seen = []</code> and <code>ans = []</code>.</p>
<p><strong>Explanation:</strong></p>
<p>Start with <code>seen = []</code> and <code>ans = []</code>.</p>
<ol>
<li>Process <code>nums[0]</code>: The first element in nums is <code>1</code>. We prepend it to the front of <code>seen</code>. Now, <code>seen == [1]</code>.</li>
@ -57,22 +47,14 @@
<p><strong class="example">Example 2:</strong></p>
<div class="example-block" style="
border-color: var(--border-tertiary);
border-left-width: 2px;
color: var(--text-secondary);
font-size: .875rem;
line-height: 1.25rem;
margin-bottom: 1rem;
margin-top: 1rem;
overflow: visible;
padding-left: 1rem;
">
<p><strong>Input:</strong> <code>nums = [1,-1,2,-1,-1]</code></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">nums = [1,-1,2,-1,-1]</span></p>
<p><strong>Output:</strong> <code>[1,2,1]</code></p>
<p><strong>Output:</strong><span class="example-io"> [1,2,1]</span></p>
<p><strong>Explanation:</strong> Start with <code>seen = []</code> and <code>ans = []</code>.</p>
<p><strong>Explanation:</strong></p>
<p>Start with <code>seen = []</code> and <code>ans = []</code>.</p>
<ol>
<li>Process <code>nums[0]</code>: The first element in nums is <code>1</code>. We prepend it to the front of <code>seen</code>. Now, <code>seen == [1]</code>.</li>

View File

@ -6,78 +6,56 @@
## Description
<p>There is a grid with <code>n + 2</code> <strong>horizontal</strong> bars and <code>m + 2</code> <strong>vertical</strong> bars, and initially containing <code>1 x 1</code> unit cells.</p>
<p>You are given the two integers, <code>n</code> and <code>m</code> and two integer arrays, <code>hBars</code> and <code>vBars</code>. The grid has <code>n + 2</code> horizontal and <code>m + 2</code> vertical bars, creating 1 x 1 unit cells. The bars are indexed starting from <code>1</code>.</p>
<p>The bars are <strong>1-indexed</strong>.</p>
<p>You can <strong>remove</strong> some of the bars in <code>hBars</code> from horizontal bars and some of the bars in <code>vBars</code> from vertical bars. Note that other bars are fixed and cannot be removed.</p>
<p>You are given the two integers, <code>n</code> and <code>m</code>.</p>
<p>You are also given two integer arrays: <code>hBars</code> and <code>vBars</code>.</p>
<ul>
<li><code>hBars</code> contains <strong>distinct</strong> horizontal bars in the range <code>[2, n + 1]</code>.</li>
<li><code>vBars</code> contains <strong>distinct</strong> vertical bars in the range <code>[2, m + 1]</code>.</li>
</ul>
<p>You are allowed to <strong>remove</strong> bars that satisfy any of the following conditions:</p>
<ul>
<li>If it is a horizontal bar, it must correspond to a value in <code>hBars</code>.</li>
<li>If it is a vertical bar, it must correspond to a value in <code>vBars</code>.</li>
</ul>
<p>Return <em>an integer denoting the <strong>maximum</strong> area of a <strong>square-shaped</strong> hole in the grid after removing some bars (<strong>possibly none</strong>).</em></p>
<p>Return an integer denoting the <strong>maximum area</strong> of a <em>square-shaped</em> hole in the grid, after removing some bars (possibly none).</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/2900-2999/2943.Maximize%20Area%20of%20Square%20Hole%20in%20Grid/images/screenshot-from-2023-11-05-22-40-25.png" style="width: 411px; height: 220px;" /></p>
<pre>
<strong>Input:</strong> n = 2, m = 1, hBars = [2,3], vBars = [2]
<strong>Output:</strong> 4
<strong>Explanation:</strong> The left image shows the initial grid formed by the bars.
The horizontal bars are in the range [1,4], and the vertical bars are in the range [1,3].
It is allowed to remove horizontal bars [2,3] and the vertical bar [2].
One way to get the maximum square-shaped hole is by removing horizontal bar 2 and vertical bar 2.
The resulting grid is shown on the right.
The hole has an area of 4.
It can be shown that it is not possible to get a square hole with an area more than 4.
Hence, the answer is 4.
</pre>
<div class="example-block" style="border-color: var(--border-tertiary); border-left-width: 2px; color: var(--text-secondary); font-size: .875rem; margin-bottom: 1rem; margin-top: 1rem; overflow: visible; padding-left: 1rem;">
<p><strong>Input: </strong><span class="example-io" style="font-family: Menlo,sans-serif; font-size: 0.85rem;">n = 2, m = 1, hBars = [2,3], vBars = [2]</span></p>
<p><strong>Output: </strong><span class="example-io" style="font-family: Menlo,sans-serif; font-size: 0.85rem;">4</span></p>
<p><strong>Explanation:</strong></p>
<p>The left image shows the initial grid formed by the bars. The horizontal bars are <code>[1,2,3,4]</code>, and the vertical bars are&nbsp;<code>[1,2,3]</code>.</p>
<p>One way to get the maximum square-shaped hole is by removing horizontal bar 2 and vertical bar 2.</p>
</div>
<p><strong class="example">Example 2:</strong></p>
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/2900-2999/2943.Maximize%20Area%20of%20Square%20Hole%20in%20Grid/images/screenshot-from-2023-11-04-17-01-02.png" style="width: 368px; height: 145px;" /></p>
<pre>
<strong>Input:</strong> n = 1, m = 1, hBars = [2], vBars = [2]
<strong>Output:</strong> 4
<strong>Explanation:</strong> The left image shows the initial grid formed by the bars.
The horizontal bars are in the range [1,3], and the vertical bars are in the range [1,3].
It is allowed to remove the horizontal bar [2] and the vertical bar [2].
To get the maximum square-shaped hole, we remove horizontal bar 2 and vertical bar 2.
The resulting grid is shown on the right.
The hole has an area of 4.
Hence, the answer is 4, and it is the maximum possible.
</pre>
<div class="example-block" style="border-color: var(--border-tertiary); border-left-width: 2px; color: var(--text-secondary); font-size: .875rem; margin-bottom: 1rem; margin-top: 1rem; overflow: visible; padding-left: 1rem;">
<p><strong>Input: </strong><span class="example-io" style="font-family: Menlo,sans-serif; font-size: 0.85rem;">n = 1, m = 1, hBars = [2], vBars = [2]</span></p>
<p><strong>Output: </strong><span class="example-io" style="font-family: Menlo,sans-serif; font-size: 0.85rem;">4</span></p>
<p><strong>Explanation:</strong></p>
<p>To get the maximum square-shaped hole, we remove horizontal bar 2 and vertical bar 2.</p>
</div>
<p><strong class="example">Example 3:</strong></p>
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/2900-2999/2943.Maximize%20Area%20of%20Square%20Hole%20in%20Grid/images/screenshot-from-2023-11-05-22-33-35.png" style="width: 648px; height: 218px;" /></p>
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/2900-2999/2943.Maximize%20Area%20of%20Square%20Hole%20in%20Grid/images/unsaved-image-2.png" style="width: 648px; height: 218px;" /></p>
<pre>
<strong>Input:</strong> n = 2, m = 3, hBars = [2,3], vBars = [2,3,4]
<strong>Output:</strong> 9
<strong>Explanation:</strong> The left image shows the initial grid formed by the bars.
The horizontal bars are in the range [1,4], and the vertical bars are in the range [1,5].
It is allowed to remove horizontal bars [2,3] and vertical bars [2,3,4].
One way to get the maximum square-shaped hole is by removing horizontal bars 2 and 3, and vertical bars 3 and 4.
The resulting grid is shown on the right.
The hole has an area of 9.
It can be shown that it is not possible to get a square hole with an area more than 9.
Hence, the answer is 9.
</pre>
<div class="example-block" style="border-color: var(--border-tertiary); border-left-width: 2px; color: var(--text-secondary); font-size: .875rem; margin-bottom: 1rem; margin-top: 1rem; overflow: visible; padding-left: 1rem;">
<p><strong>Input: </strong><span class="example-io" style="font-family: Menlo,sans-serif; font-size: 0.85rem;">n = 2, m = 3, hBars = [2,3], vBars = [2,4]</span></p>
<p><strong>Output: </strong><span class="example-io" style="font-family: Menlo,sans-serif; font-size: 0.85rem;">4</span></p>
<p><strong>Explanation:</strong></p>
<p><span style="color: var(--text-secondary); font-size: 0.875rem;">One way to get the maximum square-shaped hole is by removing horizontal bar 3, and vertical bar 4.</span></p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

View File

@ -8,18 +8,54 @@
<!-- 这里写题目描述 -->
<p>给你一个整数&nbsp;<code>k</code>&nbsp;和一个整数&nbsp;<code>x</code>&nbsp;</p>
<p>给你一个整数&nbsp;<code>k</code>&nbsp;和一个整数&nbsp;<code>x</code>&nbsp;整数&nbsp;<code>num</code>&nbsp;的价值是由它的二进制表示中,从最低有效位开始,<code>x</code><code>2x</code><code>3x</code>,以此类推,这些位置上&nbsp;<strong>设置位</strong>&nbsp;的数目来计算。下面的表格包含了如何计算价值的例子。</p>
<p><code>s</code>&nbsp;为整数&nbsp;<code>num</code>&nbsp;的下标从 <strong>1</strong>&nbsp;开始的二进制表示。我们说一个整数&nbsp;<code>num</code>&nbsp;<strong>价值</strong>&nbsp;是满足&nbsp;<code>i % x == 0</code>&nbsp;<code><font face="monospace">s[i]</font></code>&nbsp;<strong>设置位</strong>&nbsp;<code>i</code>&nbsp;的数目。</p>
<table border="1">
<tbody>
<tr>
<th>x</th>
<th>num</th>
<th>Binary Representation</th>
<th>Price</th>
</tr>
<tr>
<td>1</td>
<td>13</td>
<td><u>0</u><u>0</u><u>0</u><u>0</u><u>0</u><strong><u>1</u></strong><strong><u>1</u></strong><u>0</u><strong><u>1</u></strong></td>
<td>3</td>
</tr>
<tr>
<td>2</td>
<td>13</td>
<td>0<u>0</u>0<u>0</u>0<strong><u>1</u></strong>1<u>0</u>1</td>
<td>1</td>
</tr>
<tr>
<td>2</td>
<td>233</td>
<td>0<strong><u>1</u></strong>1<strong><u>1</u></strong>0<strong><u>1</u></strong>0<u>0</u>1</td>
<td>3</td>
</tr>
<tr>
<td>3</td>
<td>13</td>
<td><u>0</u>00<u>0</u>01<strong><u>1</u></strong>01</td>
<td>1</td>
</tr>
<tr>
<td>3</td>
<td>362</td>
<td><strong><u>1</u></strong>01<strong><u>1</u></strong>01<u>0</u>10</td>
<td>2</td>
</tr>
</tbody>
</table>
<p>请你返回<strong>&nbsp;最大</strong>&nbsp;整数<em>&nbsp;</em><code>num</code>&nbsp;,满足从 <code>1</code>&nbsp;<code>num</code>&nbsp;的所有整数的 <strong>价值</strong>&nbsp;和小于等于 <code>k</code>&nbsp;</p>
<p>&nbsp;</p>
<p><b>注意:</b></p>
<p><code>num</code>&nbsp;<strong>累加价值</strong> 是从&nbsp;<code>1</code>&nbsp;&nbsp;<code>num</code>&nbsp;的数字的 <strong></strong> 价值。如果&nbsp;<code>num</code>&nbsp;的累加价值小于或等于&nbsp;<code>k</code>&nbsp;则被认为是 <strong>廉价</strong> 的。</p>
<ul>
<li>一个整数二进制表示下 <strong>设置位</strong>&nbsp;是值为 <code>1</code>&nbsp;的数位。</li>
<li>一个整数的二进制表示下标从右到左编号,比方说如果&nbsp;<code>s == 11100</code>&nbsp;,那么&nbsp;<code>s[4] == 1</code>&nbsp;<code>s[2] == 0</code>&nbsp;</li>
</ul>
<p>请你返回<strong>&nbsp;最大</strong>&nbsp;的廉价数字。</p>
<p>&nbsp;</p>
@ -28,24 +64,159 @@
<pre>
<b>输入:</b>k = 9, x = 1
<b>输出:</b>6
<b>解释:</b>数字 1 2 3 4 5 和 6 二进制表示分别为 "1" "10" "11" "100" "101" 和 "110" 。
由于 x 等于 1 ,每个数字的价值分别为所有设置位的数目。
这些数字的所有设置位数目总数是 9 ,所以前 6 个数字的价值和为 9 。
所以答案为 6 。</pre>
<b>解释:</b>由下表所示6 是最大的廉价数字。
</pre>
<table border="1">
<tbody>
<tr>
<th>x</th>
<th>num</th>
<th>Binary Representation</th>
<th>Price</th>
<th>Accumulated Price</th>
</tr>
<tr>
<td>1</td>
<td>1</td>
<td><u>0</u><u>0</u><strong><u>1</u></strong></td>
<td>1</td>
<td>1</td>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td><u>0</u><strong><u>1</u></strong><u>0</u></td>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>1</td>
<td>3</td>
<td><u>0</u><strong><u>1</u></strong><strong><u>1</u></strong></td>
<td>2</td>
<td>4</td>
</tr>
<tr>
<td>1</td>
<td>4</td>
<td><strong><u>1</u></strong><u>0</u><u>0</u></td>
<td>1</td>
<td>5</td>
</tr>
<tr>
<td>1</td>
<td>5</td>
<td><strong><u>1</u></strong><u>0</u><strong><u>1</u></strong></td>
<td>2</td>
<td>7</td>
</tr>
<tr>
<td>1</td>
<td>6</td>
<td><strong><u>1</u></strong><strong><u>1</u></strong><u>0</u></td>
<td>2</td>
<td>9</td>
</tr>
<tr>
<td>1</td>
<td>7</td>
<td><strong><u>1</u></strong><strong><u>1</u></strong><strong><u>1</u></strong></td>
<td>3</td>
<td>12</td>
</tr>
</tbody>
</table>
<p><strong class="example">示例 2</strong></p>
<pre>
<b>输入:</b>k = 7, x = 2
<b>输出:</b>9
<b>解释:</b>由于 x 等于 2 ,我们检查每个数字的偶数位。
2 和 3 在二进制表示下的第二个数位为设置位,所以它们的价值和为 2 。
6 和 7 在二进制表示下的第二个数位为设置位,所以它们的价值和为 2 。
8 和 9 在二进制表示下的第四个数位为设置位但第二个数位不是设置位,所以它们的价值和为 2 。
数字 1 4 和 5 在二进制下偶数位都不是设置位,所以它们的价值和为 0 。
10 在二进制表示下的第二个数位和第四个数位都是设置位,所以它的价值为 2 。
前 9 个数字的价值和为 6 。
前 10 个数字的价值和为 8超过了 k = 7 ,所以答案为 9 。</pre>
<b>解释:</b>由下表所示9 是最大的廉价数字。
</pre>
<table border="1">
<tbody>
<tr>
<th>x</th>
<th>num</th>
<th>Binary Representation</th>
<th>Price</th>
<th>Accumulated Price</th>
</tr>
<tr>
<td>2</td>
<td>1</td>
<td><u>0</u>0<u>0</u>1</td>
<td>0</td>
<td>0</td>
</tr>
<tr>
<td>2</td>
<td>2</td>
<td><u>0</u>0<strong><u>1</u></strong>0</td>
<td>1</td>
<td>1</td>
</tr>
<tr>
<td>2</td>
<td>3</td>
<td><u>0</u>0<strong><u>1</u></strong>1</td>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>2</td>
<td>4</td>
<td><u>0</u>1<u>0</u>0</td>
<td>0</td>
<td>2</td>
</tr>
<tr>
<td>2</td>
<td>5</td>
<td><u>0</u>1<u>0</u>1</td>
<td>0</td>
<td>2</td>
</tr>
<tr>
<td>2</td>
<td>6</td>
<td><u>0</u>1<strong><u>1</u></strong>0</td>
<td>1</td>
<td>3</td>
</tr>
<tr>
<td>2</td>
<td>7</td>
<td><u>0</u>1<strong><u>1</u></strong>1</td>
<td>1</td>
<td>4</td>
</tr>
<tr>
<td>2</td>
<td>8</td>
<td><strong><u>1</u></strong>0<u>0</u>0</td>
<td>1</td>
<td>5</td>
</tr>
<tr>
<td>2</td>
<td>9</td>
<td><strong><u>1</u></strong>0<u>0</u>1</td>
<td>1</td>
<td>6</td>
</tr>
<tr>
<td>2</td>
<td>10</td>
<td><strong><u>1</u></strong>0<strong><u>1</u></strong>0</td>
<td>2</td>
<td>8</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>

View File

@ -6,43 +6,220 @@
## Description
<p>You are given an integer <code>k</code> and an integer <code>x</code>.</p>
<p>You are given an integer <code>k</code> and an integer <code>x</code>. The price of a number&nbsp;<code>num</code> is calculated by the count of <span data-keyword="set-bit">set bits</span> at positions <code>x</code>, <code>2x</code>, <code>3x</code>, etc., in its binary representation, starting from the least significant bit. The following table contains examples of how price is calculated.</p>
<p>Consider <code>s</code> is the <strong>1-indexed </strong>binary representation of an integer <code>num</code>. The <strong>price</strong> of a number <code>num</code> is the number of <code>i</code>&#39;s such that <code>i % x == 0</code> and <code><font face="monospace">s[i]</font></code> is a <strong>set bit</strong>.</p>
<table border="1">
<tbody>
<tr>
<th>x</th>
<th>num</th>
<th>Binary Representation</th>
<th>Price</th>
</tr>
<tr>
<td>1</td>
<td>13</td>
<td><u>0</u><u>0</u><u>0</u><u>0</u><u>0</u><strong><u>1</u></strong><strong><u>1</u></strong><u>0</u><strong><u>1</u></strong></td>
<td>3</td>
</tr>
<tr>
<td>2</td>
<td>13</td>
<td>0<u>0</u>0<u>0</u>0<strong><u>1</u></strong>1<u>0</u>1</td>
<td>1</td>
</tr>
<tr>
<td>2</td>
<td>233</td>
<td>0<strong><u>1</u></strong>1<strong><u>1</u></strong>0<strong><u>1</u></strong>0<u>0</u>1</td>
<td>3</td>
</tr>
<tr>
<td>3</td>
<td>13</td>
<td><u>0</u>00<u>0</u>01<strong><u>1</u></strong>01</td>
<td>1</td>
</tr>
<tr>
<td>3</td>
<td>362</td>
<td><strong><u>1</u></strong>01<strong><u>1</u></strong>01<u>0</u>10</td>
<td>2</td>
</tr>
</tbody>
</table>
<p>Return <em>the <b>greatest</b> integer </em><code>num</code><em> such that the sum of <strong>prices</strong> of all numbers from </em><code>1</code><em> to </em><code>num</code><em> is less than or equal to </em><code>k</code><em>.</em></p>
<p>The&nbsp;<strong>accumulated price</strong>&nbsp;of&nbsp;<code>num</code>&nbsp;is the <b>total</b>&nbsp;price of&nbsp;numbers from <code>1</code> to <code>num</code>. <code>num</code>&nbsp;is considered&nbsp;<strong>cheap</strong>&nbsp;if its accumulated price&nbsp;is less than or equal to <code>k</code>.</p>
<p><strong>Note</strong>:</p>
<ul>
<li>In the binary representation of a number <strong>set bit</strong> is a bit of value <code>1</code>.</li>
<li>The binary representation of a number will be indexed from right to left. For example, if <code>s == 11100</code>, <code>s[4] == 1</code> and <code>s[2] == 0</code>.</li>
</ul>
<p>Return the <b>greatest</b>&nbsp;cheap number.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> k = 9, x = 1
<strong>Output:</strong> 6
<strong>Explanation:</strong> The numbers 1, 2, 3, 4, 5, and 6 can be written in binary representation as &quot;1&quot;, &quot;10&quot;, &quot;11&quot;, &quot;100&quot;, &quot;101&quot;, and &quot;110&quot; respectively.
Since x is equal to 1, the price of each number is the number of its set bits.
The number of set bits in these numbers is 9. So the sum of the prices of the first 6 numbers is 9.
So the answer is 6.</pre>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">k = 9, x = 1</span></p>
<p><strong>Output:</strong> <span class="example-io">6</span></p>
<p><strong>Explanation:</strong></p>
<p>As shown in the table below, <code>6</code> is the greatest cheap number.</p>
<table border="1">
<tbody>
<tr>
<th>x</th>
<th>num</th>
<th>Binary Representation</th>
<th>Price</th>
<th>Accumulated Price</th>
</tr>
<tr>
<td>1</td>
<td>1</td>
<td><u>0</u><u>0</u><strong><u>1</u></strong></td>
<td>1</td>
<td>1</td>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td><u>0</u><strong><u>1</u></strong><u>0</u></td>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>1</td>
<td>3</td>
<td><u>0</u><strong><u>1</u></strong><strong><u>1</u></strong></td>
<td>2</td>
<td>4</td>
</tr>
<tr>
<td>1</td>
<td>4</td>
<td><strong><u>1</u></strong><u>0</u><u>0</u></td>
<td>1</td>
<td>5</td>
</tr>
<tr>
<td>1</td>
<td>5</td>
<td><strong><u>1</u></strong><u>0</u><strong><u>1</u></strong></td>
<td>2</td>
<td>7</td>
</tr>
<tr>
<td>1</td>
<td>6</td>
<td><strong><u>1</u></strong><strong><u>1</u></strong><u>0</u></td>
<td>2</td>
<td>9</td>
</tr>
<tr>
<td>1</td>
<td>7</td>
<td><strong><u>1</u></strong><strong><u>1</u></strong><strong><u>1</u></strong></td>
<td>3</td>
<td>12</td>
</tr>
</tbody>
</table>
</div>
<p><strong class="example">Example 2:</strong></p>
<pre>
<strong>Input:</strong> k = 7, x = 2
<strong>Output:</strong> 9
<strong>Explanation:</strong> Since x is equal to 2, we should just check even<sup>th</sup> bits.
The second bit of binary representation of numbers 2 and 3 is a set bit. So the sum of their prices is 2.
The second bit of binary representation of numbers 6 and 7 is a set bit. So the sum of their prices is 2.
The fourth bit of binary representation of numbers 8 and 9 is a set bit but their second bit is not. So the sum of their prices is 2.
Numbers 1, 4, and 5 don&#39;t have set bits in their even<sup>th</sup> bits in their binary representation. So the sum of their prices is 0.
The second and the fourth bit of the binary representation of the number 10 are a set bit. So its price is 2.
The sum of the prices of the first 9 numbers is 6.
Because the sum of the prices of the first 10 numbers is 8, the answer is 9.</pre>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">k = 7, x = 2</span></p>
<p><strong>Output:</strong> <span class="example-io">9</span></p>
<p><strong>Explanation:</strong></p>
<p>As shown in the table below, <code>9</code> is the greatest cheap number.</p>
<table border="1">
<tbody>
<tr>
<th>x</th>
<th>num</th>
<th>Binary Representation</th>
<th>Price</th>
<th>Accumulated Price</th>
</tr>
<tr>
<td>2</td>
<td>1</td>
<td><u>0</u>0<u>0</u>1</td>
<td>0</td>
<td>0</td>
</tr>
<tr>
<td>2</td>
<td>2</td>
<td><u>0</u>0<strong><u>1</u></strong>0</td>
<td>1</td>
<td>1</td>
</tr>
<tr>
<td>2</td>
<td>3</td>
<td><u>0</u>0<strong><u>1</u></strong>1</td>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>2</td>
<td>4</td>
<td><u>0</u>1<u>0</u>0</td>
<td>0</td>
<td>2</td>
</tr>
<tr>
<td>2</td>
<td>5</td>
<td><u>0</u>1<u>0</u>1</td>
<td>0</td>
<td>2</td>
</tr>
<tr>
<td>2</td>
<td>6</td>
<td><u>0</u>1<strong><u>1</u></strong>0</td>
<td>1</td>
<td>3</td>
</tr>
<tr>
<td>2</td>
<td>7</td>
<td><u>0</u>1<strong><u>1</u></strong>1</td>
<td>1</td>
<td>4</td>
</tr>
<tr>
<td>2</td>
<td>8</td>
<td><strong><u>1</u></strong>0<u>0</u>0</td>
<td>1</td>
<td>5</td>
</tr>
<tr>
<td>2</td>
<td>9</td>
<td><strong><u>1</u></strong>0<u>0</u>1</td>
<td>1</td>
<td>6</td>
</tr>
<tr>
<td>2</td>
<td>10</td>
<td><strong><u>1</u></strong>0<strong><u>1</u></strong>0</td>
<td>2</td>
<td>8</td>
</tr>
</tbody>
</table>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

View File

@ -1,4 +1,4 @@
# [3050. Pizza Toppings Cost Analysis](https://leetcode.cn/problems/pizza-toppings-cost-analysis)
# [3050. 披萨配料成本分析](https://leetcode.cn/problems/pizza-toppings-cost-analysis)
[English Version](/solution/3000-3099/3050.Pizza%20Toppings%20Cost%20Analysis/README_EN.md)

View File

@ -1,4 +1,4 @@
# [3051. Find Candidates for Data Scientist Position](https://leetcode.cn/problems/find-candidates-for-data-scientist-position)
# [3051. 寻找数据科学家职位的候选人](https://leetcode.cn/problems/find-candidates-for-data-scientist-position)
[English Version](/solution/3000-3099/3051.Find%20Candidates%20for%20Data%20Scientist%20Position/README_EN.md)

View File

@ -1,4 +1,4 @@
# [3052. Maximize Items](https://leetcode.cn/problems/maximize-items)
# [3052. 最大化商品](https://leetcode.cn/problems/maximize-items)
[English Version](/solution/3000-3099/3052.Maximize%20Items/README_EN.md)

View File

@ -1,4 +1,4 @@
# [3053. Classifying Triangles by Lengths](https://leetcode.cn/problems/classifying-triangles-by-lengths)
# [3053. 根据长度分类三角形](https://leetcode.cn/problems/classifying-triangles-by-lengths)
[English Version](/solution/3000-3099/3053.Classifying%20Triangles%20by%20Lengths/README_EN.md)

View File

@ -1,4 +1,4 @@
# [3054. Binary Tree Nodes](https://leetcode.cn/problems/binary-tree-nodes)
# [3054. 二叉树节点](https://leetcode.cn/problems/binary-tree-nodes)
[English Version](/solution/3000-3099/3054.Binary%20Tree%20Nodes/README_EN.md)

View File

@ -1,4 +1,4 @@
# [3055. Top Percentile Fraud](https://leetcode.cn/problems/top-percentile-fraud)
# [3055. 最高欺诈百分位数](https://leetcode.cn/problems/top-percentile-fraud)
[English Version](/solution/3000-3099/3055.Top%20Percentile%20Fraud/README_EN.md)

View File

@ -1,4 +1,4 @@
# [3056. Snaps Analysis](https://leetcode.cn/problems/snaps-analysis)
# [3056. 快照分析](https://leetcode.cn/problems/snaps-analysis)
[English Version](/solution/3000-3099/3056.Snaps%20Analysis/README_EN.md)

View File

@ -1,4 +1,4 @@
# [3057. Employees Project Allocation](https://leetcode.cn/problems/employees-project-allocation)
# [3057. 员工项目分配](https://leetcode.cn/problems/employees-project-allocation)
[English Version](/solution/3000-3099/3057.Employees%20Project%20Allocation/README_EN.md)

View File

@ -1,4 +1,4 @@
# [3058. Friends With No Mutual Friends](https://leetcode.cn/problems/friends-with-no-mutual-friends)
# [3058. 没有共同朋友的朋友](https://leetcode.cn/problems/friends-with-no-mutual-friends)
[English Version](/solution/3000-3099/3058.Friends%20With%20No%20Mutual%20Friends/README_EN.md)

View File

@ -1,4 +1,4 @@
# [3059. Find All Unique Email Domains](https://leetcode.cn/problems/find-all-unique-email-domains)
# [3059. 找到所有不同的邮件域名](https://leetcode.cn/problems/find-all-unique-email-domains)
[English Version](/solution/3000-3099/3059.Find%20All%20Unique%20Email%20Domains/README_EN.md)

View File

@ -2,7 +2,7 @@
[English Version](/solution/3000-3099/3087.Find%20Trending%20Hashtags/README_EN.md)
<!-- tags: -->
<!-- tags:数据库 -->
## 题目描述

View File

@ -2,7 +2,7 @@
[中文文档](/solution/3000-3099/3087.Find%20Trending%20Hashtags/README.md)
<!-- tags: -->
<!-- tags:Database -->
## Description

View File

@ -2,7 +2,7 @@
[English Version](/solution/3000-3099/3088.Make%20String%20Anti-palindrome/README_EN.md)
<!-- tags: -->
<!-- tags:贪心,字符串,排序 -->
## 题目描述

View File

@ -2,7 +2,7 @@
[中文文档](/solution/3000-3099/3088.Make%20String%20Anti-palindrome/README.md)
<!-- tags: -->
<!-- tags:Greedy,String,Sorting -->
## Description

View File

@ -1,8 +1,8 @@
# [3089. Find Bursty Behavior](https://leetcode.cn/problems/find-bursty-behavior)
# [3089. 查找突发行为](https://leetcode.cn/problems/find-bursty-behavior)
[English Version](/solution/3000-3099/3089.Find%20Bursty%20Behavior/README_EN.md)
<!-- tags: -->
<!-- tags:数据库 -->
## 题目描述

View File

@ -2,7 +2,7 @@
[中文文档](/solution/3000-3099/3089.Find%20Bursty%20Behavior/README.md)
<!-- tags: -->
<!-- tags:Database -->
## Description

View File

@ -2,7 +2,7 @@
[English Version](/solution/3000-3099/3090.Maximum%20Length%20Substring%20With%20Two%20Occurrences/README_EN.md)
<!-- tags: -->
<!-- tags:哈希表,字符串,滑动窗口 -->
## 题目描述

View File

@ -2,7 +2,7 @@
[中文文档](/solution/3000-3099/3090.Maximum%20Length%20Substring%20With%20Two%20Occurrences/README.md)
<!-- tags: -->
<!-- tags:Hash Table,String,Sliding Window -->
## Description

View File

@ -2,7 +2,7 @@
[English Version](/solution/3000-3099/3091.Apply%20Operations%20to%20Make%20Sum%20of%20Array%20Greater%20Than%20or%20Equal%20to%20k/README_EN.md)
<!-- tags: -->
<!-- tags:贪心,数学,枚举 -->
## 题目描述

View File

@ -2,7 +2,7 @@
[中文文档](/solution/3000-3099/3091.Apply%20Operations%20to%20Make%20Sum%20of%20Array%20Greater%20Than%20or%20Equal%20to%20k/README.md)
<!-- tags: -->
<!-- tags:Greedy,Math,Enumeration -->
## Description

View File

@ -2,7 +2,7 @@
[English Version](/solution/3000-3099/3092.Most%20Frequent%20IDs/README_EN.md)
<!-- tags: -->
<!-- tags:数组,哈希表,有序集合,堆(优先队列) -->
## 题目描述

View File

@ -2,7 +2,7 @@
[中文文档](/solution/3000-3099/3092.Most%20Frequent%20IDs/README.md)
<!-- tags: -->
<!-- tags:Array,Hash Table,Ordered Set,Heap (Priority Queue) -->
## Description

View File

@ -2,7 +2,7 @@
[English Version](/solution/3000-3099/3093.Longest%20Common%20Suffix%20Queries/README_EN.md)
<!-- tags: -->
<!-- tags:字典树,数组,字符串 -->
## 题目描述

View File

@ -2,7 +2,7 @@
[中文文档](/solution/3000-3099/3093.Longest%20Common%20Suffix%20Queries/README.md)
<!-- tags: -->
<!-- tags:Trie,Array,String -->
## Description

View File

@ -259,20 +259,20 @@
| 2993 | [发生在周五的交易 I](/solution/2900-2999/2993.Friday%20Purchases%20I/README.md) | `数据库` | 中等 | 🔒 |
| 2994 | [发生在周五的交易 II](/solution/2900-2999/2994.Friday%20Purchases%20II/README.md) | `数据库` | 困难 | 🔒 |
| 2995 | [观众变主播](/solution/2900-2999/2995.Viewers%20Turned%20Streamers/README.md) | `数据库` | 困难 | 🔒 |
| 3050 | [Pizza Toppings Cost Analysis](/solution/3000-3099/3050.Pizza%20Toppings%20Cost%20Analysis/README.md) | `数据库` | 中等 | 🔒 |
| 3051 | [Find Candidates for Data Scientist Position](/solution/3000-3099/3051.Find%20Candidates%20for%20Data%20Scientist%20Position/README.md) | `数据库` | 简单 | 🔒 |
| 3052 | [Maximize Items](/solution/3000-3099/3052.Maximize%20Items/README.md) | `数据库` | 困难 | 🔒 |
| 3053 | [Classifying Triangles by Lengths](/solution/3000-3099/3053.Classifying%20Triangles%20by%20Lengths/README.md) | `数据库` | 简单 | 🔒 |
| 3054 | [Binary Tree Nodes](/solution/3000-3099/3054.Binary%20Tree%20Nodes/README.md) | `数据库` | 中等 | 🔒 |
| 3055 | [Top Percentile Fraud](/solution/3000-3099/3055.Top%20Percentile%20Fraud/README.md) | `数据库` | 中等 | 🔒 |
| 3056 | [Snaps Analysis](/solution/3000-3099/3056.Snaps%20Analysis/README.md) | `数据库` | 中等 | 🔒 |
| 3057 | [Employees Project Allocation](/solution/3000-3099/3057.Employees%20Project%20Allocation/README.md) | `数据库` | 困难 | 🔒 |
| 3058 | [Friends With No Mutual Friends](/solution/3000-3099/3058.Friends%20With%20No%20Mutual%20Friends/README.md) | `数据库` | 中等 | 🔒 |
| 3059 | [Find All Unique Email Domains](/solution/3000-3099/3059.Find%20All%20Unique%20Email%20Domains/README.md) | `数据库` | 简单 | 🔒 |
| 3050 | [披萨配料成本分析](/solution/3000-3099/3050.Pizza%20Toppings%20Cost%20Analysis/README.md) | `数据库` | 中等 | 🔒 |
| 3051 | [寻找数据科学家职位的候选人](/solution/3000-3099/3051.Find%20Candidates%20for%20Data%20Scientist%20Position/README.md) | `数据库` | 简单 | 🔒 |
| 3052 | [最大化商品](/solution/3000-3099/3052.Maximize%20Items/README.md) | `数据库` | 困难 | 🔒 |
| 3053 | [根据长度分类三角形](/solution/3000-3099/3053.Classifying%20Triangles%20by%20Lengths/README.md) | `数据库` | 简单 | 🔒 |
| 3054 | [二叉树节点](/solution/3000-3099/3054.Binary%20Tree%20Nodes/README.md) | `数据库` | 中等 | 🔒 |
| 3055 | [最高欺诈百分位数](/solution/3000-3099/3055.Top%20Percentile%20Fraud/README.md) | `数据库` | 中等 | 🔒 |
| 3056 | [快照分析](/solution/3000-3099/3056.Snaps%20Analysis/README.md) | `数据库` | 中等 | 🔒 |
| 3057 | [员工项目分配](/solution/3000-3099/3057.Employees%20Project%20Allocation/README.md) | `数据库` | 困难 | 🔒 |
| 3058 | [没有共同朋友的朋友](/solution/3000-3099/3058.Friends%20With%20No%20Mutual%20Friends/README.md) | `数据库` | 中等 | 🔒 |
| 3059 | [找到所有不同的邮件域名](/solution/3000-3099/3059.Find%20All%20Unique%20Email%20Domains/README.md) | `数据库` | 简单 | 🔒 |
| 3060 | [时间范围内的用户活动](/solution/3000-3099/3060.User%20Activities%20within%20Time%20Bounds/README.md) | `数据库` | 困难 | 🔒 |
| 3061 | [计算滞留雨水](/solution/3000-3099/3061.Calculate%20Trapping%20Rain%20Water/README.md) | `数据库` | 困难 | 🔒 |
| 3087 | [查找热门话题标签](/solution/3000-3099/3087.Find%20Trending%20Hashtags/README.md) | | 中等 | 🔒 |
| 3089 | [Find Bursty Behavior](/solution/3000-3099/3089.Find%20Bursty%20Behavior/README.md) | | 中等 | 🔒 |
| 3087 | [查找热门话题标签](/solution/3000-3099/3087.Find%20Trending%20Hashtags/README.md) | `数据库` | 中等 | 🔒 |
| 3089 | [查找突发行为](/solution/3000-3099/3089.Find%20Bursty%20Behavior/README.md) | `数据库` | 中等 | 🔒 |
## 版权

View File

@ -269,8 +269,8 @@ Press <kbd>Control</kbd> + <kbd>F</kbd>(or <kbd>Command</kbd> + <kbd>F</kbd> on
| 3059 | [Find All Unique Email Domains](/solution/3000-3099/3059.Find%20All%20Unique%20Email%20Domains/README_EN.md) | `Database` | Easy | 🔒 |
| 3060 | [User Activities within Time Bounds](/solution/3000-3099/3060.User%20Activities%20within%20Time%20Bounds/README_EN.md) | `Database` | Hard | 🔒 |
| 3061 | [Calculate Trapping Rain Water](/solution/3000-3099/3061.Calculate%20Trapping%20Rain%20Water/README_EN.md) | `Database` | Hard | 🔒 |
| 3087 | [Find Trending Hashtags](/solution/3000-3099/3087.Find%20Trending%20Hashtags/README_EN.md) | | Medium | 🔒 |
| 3089 | [Find Bursty Behavior](/solution/3000-3099/3089.Find%20Bursty%20Behavior/README_EN.md) | | Medium | 🔒 |
| 3087 | [Find Trending Hashtags](/solution/3000-3099/3087.Find%20Trending%20Hashtags/README_EN.md) | `Database` | Medium | 🔒 |
| 3089 | [Find Bursty Behavior](/solution/3000-3099/3089.Find%20Bursty%20Behavior/README_EN.md) | `Database` | Medium | 🔒 |
## Copyright

View File

@ -331,7 +331,7 @@
| 0318 | [最大单词长度乘积](/solution/0300-0399/0318.Maximum%20Product%20of%20Word%20Lengths/README.md) | `位运算`,`数组`,`字符串` | 中等 | |
| 0319 | [灯泡开关](/solution/0300-0399/0319.Bulb%20Switcher/README.md) | `脑筋急转弯`,`数学` | 中等 | |
| 0320 | [列举单词的全部缩写](/solution/0300-0399/0320.Generalized%20Abbreviation/README.md) | `位运算`,`字符串`,`回溯` | 中等 | 🔒 |
| 0321 | [拼接最大数](/solution/0300-0399/0321.Create%20Maximum%20Number/README.md) | `栈`,`贪心`,`单调栈` | 困难 | |
| 0321 | [拼接最大数](/solution/0300-0399/0321.Create%20Maximum%20Number/README.md) | `栈`,`贪心`,`数组`,`双指针`,`单调栈` | 困难 | |
| 0322 | [零钱兑换](/solution/0300-0399/0322.Coin%20Change/README.md) | `广度优先搜索`,`数组`,`动态规划` | 中等 | |
| 0323 | [无向图中连通分量的数目](/solution/0300-0399/0323.Number%20of%20Connected%20Components%20in%20an%20Undirected%20Graph/README.md) | `深度优先搜索`,`广度优先搜索`,`并查集`,`图` | 中等 | 🔒 |
| 0324 | [摆动排序 II](/solution/0300-0399/0324.Wiggle%20Sort%20II/README.md) | `数组`,`分治`,`快速选择`,`排序` | 中等 | |
@ -850,7 +850,7 @@
| 0837 | [新 21 点](/solution/0800-0899/0837.New%2021%20Game/README.md) | `数学`,`动态规划`,`滑动窗口`,`概率与统计` | 中等 | 第 85 场周赛 |
| 0838 | [推多米诺](/solution/0800-0899/0838.Push%20Dominoes/README.md) | `双指针`,`字符串`,`动态规划` | 中等 | 第 85 场周赛 |
| 0839 | [相似字符串组](/solution/0800-0899/0839.Similar%20String%20Groups/README.md) | `深度优先搜索`,`广度优先搜索`,`并查集`,`数组`,`哈希表`,`字符串` | 困难 | 第 85 场周赛 |
| 0840 | [矩阵中的幻方](/solution/0800-0899/0840.Magic%20Squares%20In%20Grid/README.md) | `数组`,`数学`,`矩阵` | 中等 | 第 86 场周赛 |
| 0840 | [矩阵中的幻方](/solution/0800-0899/0840.Magic%20Squares%20In%20Grid/README.md) | `数组`,`哈希表`,`数学`,`矩阵` | 中等 | 第 86 场周赛 |
| 0841 | [钥匙和房间](/solution/0800-0899/0841.Keys%20and%20Rooms/README.md) | `深度优先搜索`,`广度优先搜索`,`图` | 中等 | 第 86 场周赛 |
| 0842 | [将数组拆分成斐波那契序列](/solution/0800-0899/0842.Split%20Array%20into%20Fibonacci%20Sequence/README.md) | `字符串`,`回溯` | 中等 | 第 86 场周赛 |
| 0843 | [猜猜这个单词](/solution/0800-0899/0843.Guess%20the%20Word/README.md) | `数组`,`数学`,`字符串`,`博弈`,`交互` | 困难 | 第 86 场周赛 |
@ -2627,7 +2627,7 @@
| 2614 | [对角线上的质数](/solution/2600-2699/2614.Prime%20In%20Diagonal/README.md) | `数组`,`数学`,`矩阵`,`数论` | 简单 | 第 340 场周赛 |
| 2615 | [等值距离和](/solution/2600-2699/2615.Sum%20of%20Distances/README.md) | `数组`,`哈希表`,`前缀和` | 中等 | 第 340 场周赛 |
| 2616 | [最小化数对的最大差值](/solution/2600-2699/2616.Minimize%20the%20Maximum%20Difference%20of%20Pairs/README.md) | `贪心`,`数组`,`二分查找` | 中等 | 第 340 场周赛 |
| 2617 | [网格图中最少访问的格子数](/solution/2600-2699/2617.Minimum%20Number%20of%20Visited%20Cells%20in%20a%20Grid/README.md) | `栈`,`并查集`,`树状数组`,`线段树`,`数组`,`二分查找`,`动态规划` | 困难 | 第 340 场周赛 |
| 2617 | [网格图中最少访问的格子数](/solution/2600-2699/2617.Minimum%20Number%20of%20Visited%20Cells%20in%20a%20Grid/README.md) | `栈`,`广度优先搜索`,`并查集`,`数组`,`动态规划`,`矩阵`,`单调栈`,`堆(优先队列)` | 困难 | 第 340 场周赛 |
| 2618 | [检查是否是类的对象实例](/solution/2600-2699/2618.Check%20if%20Object%20Instance%20of%20Class/README.md) | | 中等 | |
| 2619 | [数组原型对象的最后一个元素](/solution/2600-2699/2619.Array%20Prototype%20Last/README.md) | | 简单 | |
| 2620 | [计数器](/solution/2600-2699/2620.Counter/README.md) | | 简单 | |
@ -3060,16 +3060,16 @@
| 3047 | [求交集区域内的最大正方形面积](/solution/3000-3099/3047.Find%20the%20Largest%20Area%20of%20Square%20Inside%20Two%20Rectangles/README.md) | `几何`,`数组`,`数学` | 中等 | 第 386 场周赛 |
| 3048 | [标记所有下标的最早秒数 I](/solution/3000-3099/3048.Earliest%20Second%20to%20Mark%20Indices%20I/README.md) | `数组`,`二分查找` | 中等 | 第 386 场周赛 |
| 3049 | [标记所有下标的最早秒数 II](/solution/3000-3099/3049.Earliest%20Second%20to%20Mark%20Indices%20II/README.md) | `贪心`,`数组`,`二分查找`,`堆(优先队列)` | 困难 | 第 386 场周赛 |
| 3050 | [Pizza Toppings Cost Analysis](/solution/3000-3099/3050.Pizza%20Toppings%20Cost%20Analysis/README.md) | `数据库` | 中等 | 🔒 |
| 3051 | [Find Candidates for Data Scientist Position](/solution/3000-3099/3051.Find%20Candidates%20for%20Data%20Scientist%20Position/README.md) | `数据库` | 简单 | 🔒 |
| 3052 | [Maximize Items](/solution/3000-3099/3052.Maximize%20Items/README.md) | `数据库` | 困难 | 🔒 |
| 3053 | [Classifying Triangles by Lengths](/solution/3000-3099/3053.Classifying%20Triangles%20by%20Lengths/README.md) | `数据库` | 简单 | 🔒 |
| 3054 | [Binary Tree Nodes](/solution/3000-3099/3054.Binary%20Tree%20Nodes/README.md) | `数据库` | 中等 | 🔒 |
| 3055 | [Top Percentile Fraud](/solution/3000-3099/3055.Top%20Percentile%20Fraud/README.md) | `数据库` | 中等 | 🔒 |
| 3056 | [Snaps Analysis](/solution/3000-3099/3056.Snaps%20Analysis/README.md) | `数据库` | 中等 | 🔒 |
| 3057 | [Employees Project Allocation](/solution/3000-3099/3057.Employees%20Project%20Allocation/README.md) | `数据库` | 困难 | 🔒 |
| 3058 | [Friends With No Mutual Friends](/solution/3000-3099/3058.Friends%20With%20No%20Mutual%20Friends/README.md) | `数据库` | 中等 | 🔒 |
| 3059 | [Find All Unique Email Domains](/solution/3000-3099/3059.Find%20All%20Unique%20Email%20Domains/README.md) | `数据库` | 简单 | 🔒 |
| 3050 | [披萨配料成本分析](/solution/3000-3099/3050.Pizza%20Toppings%20Cost%20Analysis/README.md) | `数据库` | 中等 | 🔒 |
| 3051 | [寻找数据科学家职位的候选人](/solution/3000-3099/3051.Find%20Candidates%20for%20Data%20Scientist%20Position/README.md) | `数据库` | 简单 | 🔒 |
| 3052 | [最大化商品](/solution/3000-3099/3052.Maximize%20Items/README.md) | `数据库` | 困难 | 🔒 |
| 3053 | [根据长度分类三角形](/solution/3000-3099/3053.Classifying%20Triangles%20by%20Lengths/README.md) | `数据库` | 简单 | 🔒 |
| 3054 | [二叉树节点](/solution/3000-3099/3054.Binary%20Tree%20Nodes/README.md) | `数据库` | 中等 | 🔒 |
| 3055 | [最高欺诈百分位数](/solution/3000-3099/3055.Top%20Percentile%20Fraud/README.md) | `数据库` | 中等 | 🔒 |
| 3056 | [快照分析](/solution/3000-3099/3056.Snaps%20Analysis/README.md) | `数据库` | 中等 | 🔒 |
| 3057 | [员工项目分配](/solution/3000-3099/3057.Employees%20Project%20Allocation/README.md) | `数据库` | 困难 | 🔒 |
| 3058 | [没有共同朋友的朋友](/solution/3000-3099/3058.Friends%20With%20No%20Mutual%20Friends/README.md) | `数据库` | 中等 | 🔒 |
| 3059 | [找到所有不同的邮件域名](/solution/3000-3099/3059.Find%20All%20Unique%20Email%20Domains/README.md) | `数据库` | 简单 | 🔒 |
| 3060 | [时间范围内的用户活动](/solution/3000-3099/3060.User%20Activities%20within%20Time%20Bounds/README.md) | `数据库` | 困难 | 🔒 |
| 3061 | [计算滞留雨水](/solution/3000-3099/3061.Calculate%20Trapping%20Rain%20Water/README.md) | `数据库` | 困难 | 🔒 |
| 3062 | [链表游戏的获胜者](/solution/3000-3099/3062.Winner%20of%20the%20Linked%20List%20Game/README.md) | `链表` | 简单 | 🔒 |
@ -3097,13 +3097,13 @@
| 3084 | [统计以给定字符开头和结尾的子字符串总数](/solution/3000-3099/3084.Count%20Substrings%20Starting%20and%20Ending%20with%20Given%20Character/README.md) | `数学`,`字符串`,`计数` | 中等 | 第 389 场周赛 |
| 3085 | [成为 K 特殊字符串需要删除的最少字符数](/solution/3000-3099/3085.Minimum%20Deletions%20to%20Make%20String%20K-Special/README.md) | `贪心`,`哈希表`,`字符串`,`计数`,`排序` | 中等 | 第 389 场周赛 |
| 3086 | [拾起 K 个 1 需要的最少行动次数](/solution/3000-3099/3086.Minimum%20Moves%20to%20Pick%20K%20Ones/README.md) | `贪心`,`数组`,`前缀和`,`滑动窗口` | 困难 | 第 389 场周赛 |
| 3087 | [查找热门话题标签](/solution/3000-3099/3087.Find%20Trending%20Hashtags/README.md) | | 中等 | 🔒 |
| 3088 | [使字符串反回文](/solution/3000-3099/3088.Make%20String%20Anti-palindrome/README.md) | | 困难 | 🔒 |
| 3089 | [Find Bursty Behavior](/solution/3000-3099/3089.Find%20Bursty%20Behavior/README.md) | | 中等 | 🔒 |
| 3090 | [每个字符最多出现两次的最长子字符串](/solution/3000-3099/3090.Maximum%20Length%20Substring%20With%20Two%20Occurrences/README.md) | | 简单 | 第 390 场周赛 |
| 3091 | [执行操作使数据元素之和大于等于 K](/solution/3000-3099/3091.Apply%20Operations%20to%20Make%20Sum%20of%20Array%20Greater%20Than%20or%20Equal%20to%20k/README.md) | | 中等 | 第 390 场周赛 |
| 3092 | [最高频率的 ID](/solution/3000-3099/3092.Most%20Frequent%20IDs/README.md) | | 中等 | 第 390 场周赛 |
| 3093 | [最长公共后缀查询](/solution/3000-3099/3093.Longest%20Common%20Suffix%20Queries/README.md) | | 困难 | 第 390 场周赛 |
| 3087 | [查找热门话题标签](/solution/3000-3099/3087.Find%20Trending%20Hashtags/README.md) | `数据库` | 中等 | 🔒 |
| 3088 | [使字符串反回文](/solution/3000-3099/3088.Make%20String%20Anti-palindrome/README.md) | `贪心`,`字符串`,`排序` | 困难 | 🔒 |
| 3089 | [查找突发行为](/solution/3000-3099/3089.Find%20Bursty%20Behavior/README.md) | `数据库` | 中等 | 🔒 |
| 3090 | [每个字符最多出现两次的最长子字符串](/solution/3000-3099/3090.Maximum%20Length%20Substring%20With%20Two%20Occurrences/README.md) | `哈希表`,`字符串`,`滑动窗口` | 简单 | 第 390 场周赛 |
| 3091 | [执行操作使数据元素之和大于等于 K](/solution/3000-3099/3091.Apply%20Operations%20to%20Make%20Sum%20of%20Array%20Greater%20Than%20or%20Equal%20to%20k/README.md) | `贪心`,`数学`,`枚举` | 中等 | 第 390 场周赛 |
| 3092 | [最高频率的 ID](/solution/3000-3099/3092.Most%20Frequent%20IDs/README.md) | `数组`,`哈希表`,`有序集合`,`堆(优先队列)` | 中等 | 第 390 场周赛 |
| 3093 | [最长公共后缀查询](/solution/3000-3099/3093.Longest%20Common%20Suffix%20Queries/README.md) | `字典树`,`数组`,`字符串` | 困难 | 第 390 场周赛 |
## 版权

View File

@ -329,7 +329,7 @@ Press <kbd>Control</kbd> + <kbd>F</kbd>(or <kbd>Command</kbd> + <kbd>F</kbd> on
| 0318 | [Maximum Product of Word Lengths](/solution/0300-0399/0318.Maximum%20Product%20of%20Word%20Lengths/README_EN.md) | `Bit Manipulation`,`Array`,`String` | Medium | |
| 0319 | [Bulb Switcher](/solution/0300-0399/0319.Bulb%20Switcher/README_EN.md) | `Brainteaser`,`Math` | Medium | |
| 0320 | [Generalized Abbreviation](/solution/0300-0399/0320.Generalized%20Abbreviation/README_EN.md) | `Bit Manipulation`,`String`,`Backtracking` | Medium | 🔒 |
| 0321 | [Create Maximum Number](/solution/0300-0399/0321.Create%20Maximum%20Number/README_EN.md) | `Stack`,`Greedy`,`Monotonic Stack` | Hard | |
| 0321 | [Create Maximum Number](/solution/0300-0399/0321.Create%20Maximum%20Number/README_EN.md) | `Stack`,`Greedy`,`Array`,`Two Pointers`,`Monotonic Stack` | Hard | |
| 0322 | [Coin Change](/solution/0300-0399/0322.Coin%20Change/README_EN.md) | `Breadth-First Search`,`Array`,`Dynamic Programming` | Medium | |
| 0323 | [Number of Connected Components in an Undirected Graph](/solution/0300-0399/0323.Number%20of%20Connected%20Components%20in%20an%20Undirected%20Graph/README_EN.md) | `Depth-First Search`,`Breadth-First Search`,`Union Find`,`Graph` | Medium | 🔒 |
| 0324 | [Wiggle Sort II](/solution/0300-0399/0324.Wiggle%20Sort%20II/README_EN.md) | `Array`,`Divide and Conquer`,`Quickselect`,`Sorting` | Medium | |
@ -848,7 +848,7 @@ Press <kbd>Control</kbd> + <kbd>F</kbd>(or <kbd>Command</kbd> + <kbd>F</kbd> on
| 0837 | [New 21 Game](/solution/0800-0899/0837.New%2021%20Game/README_EN.md) | `Math`,`Dynamic Programming`,`Sliding Window`,`Probability and Statistics` | Medium | Weekly Contest 85 |
| 0838 | [Push Dominoes](/solution/0800-0899/0838.Push%20Dominoes/README_EN.md) | `Two Pointers`,`String`,`Dynamic Programming` | Medium | Weekly Contest 85 |
| 0839 | [Similar String Groups](/solution/0800-0899/0839.Similar%20String%20Groups/README_EN.md) | `Depth-First Search`,`Breadth-First Search`,`Union Find`,`Array`,`Hash Table`,`String` | Hard | Weekly Contest 85 |
| 0840 | [Magic Squares In Grid](/solution/0800-0899/0840.Magic%20Squares%20In%20Grid/README_EN.md) | `Array`,`Math`,`Matrix` | Medium | Weekly Contest 86 |
| 0840 | [Magic Squares In Grid](/solution/0800-0899/0840.Magic%20Squares%20In%20Grid/README_EN.md) | `Array`,`Hash Table`,`Math`,`Matrix` | Medium | Weekly Contest 86 |
| 0841 | [Keys and Rooms](/solution/0800-0899/0841.Keys%20and%20Rooms/README_EN.md) | `Depth-First Search`,`Breadth-First Search`,`Graph` | Medium | Weekly Contest 86 |
| 0842 | [Split Array into Fibonacci Sequence](/solution/0800-0899/0842.Split%20Array%20into%20Fibonacci%20Sequence/README_EN.md) | `String`,`Backtracking` | Medium | Weekly Contest 86 |
| 0843 | [Guess the Word](/solution/0800-0899/0843.Guess%20the%20Word/README_EN.md) | `Array`,`Math`,`String`,`Game Theory`,`Interactive` | Hard | Weekly Contest 86 |
@ -2625,7 +2625,7 @@ Press <kbd>Control</kbd> + <kbd>F</kbd>(or <kbd>Command</kbd> + <kbd>F</kbd> on
| 2614 | [Prime In Diagonal](/solution/2600-2699/2614.Prime%20In%20Diagonal/README_EN.md) | `Array`,`Math`,`Matrix`,`Number Theory` | Easy | Weekly Contest 340 |
| 2615 | [Sum of Distances](/solution/2600-2699/2615.Sum%20of%20Distances/README_EN.md) | `Array`,`Hash Table`,`Prefix Sum` | Medium | Weekly Contest 340 |
| 2616 | [Minimize the Maximum Difference of Pairs](/solution/2600-2699/2616.Minimize%20the%20Maximum%20Difference%20of%20Pairs/README_EN.md) | `Greedy`,`Array`,`Binary Search` | Medium | Weekly Contest 340 |
| 2617 | [Minimum Number of Visited Cells in a Grid](/solution/2600-2699/2617.Minimum%20Number%20of%20Visited%20Cells%20in%20a%20Grid/README_EN.md) | `Stack`,`Union Find`,`Binary Indexed Tree`,`Segment Tree`,`Array`,`Binary Search`,`Dynamic Programming` | Hard | Weekly Contest 340 |
| 2617 | [Minimum Number of Visited Cells in a Grid](/solution/2600-2699/2617.Minimum%20Number%20of%20Visited%20Cells%20in%20a%20Grid/README_EN.md) | `Stack`,`Breadth-First Search`,`Union Find`,`Array`,`Dynamic Programming`,`Matrix`,`Monotonic Stack`,`Heap (Priority Queue)` | Hard | Weekly Contest 340 |
| 2618 | [Check if Object Instance of Class](/solution/2600-2699/2618.Check%20if%20Object%20Instance%20of%20Class/README_EN.md) | | Medium | |
| 2619 | [Array Prototype Last](/solution/2600-2699/2619.Array%20Prototype%20Last/README_EN.md) | | Easy | |
| 2620 | [Counter](/solution/2600-2699/2620.Counter/README_EN.md) | | Easy | |
@ -3095,13 +3095,13 @@ Press <kbd>Control</kbd> + <kbd>F</kbd>(or <kbd>Command</kbd> + <kbd>F</kbd> on
| 3084 | [Count Substrings Starting and Ending with Given Character](/solution/3000-3099/3084.Count%20Substrings%20Starting%20and%20Ending%20with%20Given%20Character/README_EN.md) | `Math`,`String`,`Counting` | Medium | Weekly Contest 389 |
| 3085 | [Minimum Deletions to Make String K-Special](/solution/3000-3099/3085.Minimum%20Deletions%20to%20Make%20String%20K-Special/README_EN.md) | `Greedy`,`Hash Table`,`String`,`Counting`,`Sorting` | Medium | Weekly Contest 389 |
| 3086 | [Minimum Moves to Pick K Ones](/solution/3000-3099/3086.Minimum%20Moves%20to%20Pick%20K%20Ones/README_EN.md) | `Greedy`,`Array`,`Prefix Sum`,`Sliding Window` | Hard | Weekly Contest 389 |
| 3087 | [Find Trending Hashtags](/solution/3000-3099/3087.Find%20Trending%20Hashtags/README_EN.md) | | Medium | 🔒 |
| 3088 | [Make String Anti-palindrome](/solution/3000-3099/3088.Make%20String%20Anti-palindrome/README_EN.md) | | Hard | 🔒 |
| 3089 | [Find Bursty Behavior](/solution/3000-3099/3089.Find%20Bursty%20Behavior/README_EN.md) | | Medium | 🔒 |
| 3090 | [Maximum Length Substring With Two Occurrences](/solution/3000-3099/3090.Maximum%20Length%20Substring%20With%20Two%20Occurrences/README_EN.md) | | Easy | Weekly Contest 390 |
| 3091 | [Apply Operations to Make Sum of Array Greater Than or Equal to k](/solution/3000-3099/3091.Apply%20Operations%20to%20Make%20Sum%20of%20Array%20Greater%20Than%20or%20Equal%20to%20k/README_EN.md) | | Medium | Weekly Contest 390 |
| 3092 | [Most Frequent IDs](/solution/3000-3099/3092.Most%20Frequent%20IDs/README_EN.md) | | Medium | Weekly Contest 390 |
| 3093 | [Longest Common Suffix Queries](/solution/3000-3099/3093.Longest%20Common%20Suffix%20Queries/README_EN.md) | | Hard | Weekly Contest 390 |
| 3087 | [Find Trending Hashtags](/solution/3000-3099/3087.Find%20Trending%20Hashtags/README_EN.md) | `Database` | Medium | 🔒 |
| 3088 | [Make String Anti-palindrome](/solution/3000-3099/3088.Make%20String%20Anti-palindrome/README_EN.md) | `Greedy`,`String`,`Sorting` | Hard | 🔒 |
| 3089 | [Find Bursty Behavior](/solution/3000-3099/3089.Find%20Bursty%20Behavior/README_EN.md) | `Database` | Medium | 🔒 |
| 3090 | [Maximum Length Substring With Two Occurrences](/solution/3000-3099/3090.Maximum%20Length%20Substring%20With%20Two%20Occurrences/README_EN.md) | `Hash Table`,`String`,`Sliding Window` | Easy | Weekly Contest 390 |
| 3091 | [Apply Operations to Make Sum of Array Greater Than or Equal to k](/solution/3000-3099/3091.Apply%20Operations%20to%20Make%20Sum%20of%20Array%20Greater%20Than%20or%20Equal%20to%20k/README_EN.md) | `Greedy`,`Math`,`Enumeration` | Medium | Weekly Contest 390 |
| 3092 | [Most Frequent IDs](/solution/3000-3099/3092.Most%20Frequent%20IDs/README_EN.md) | `Array`,`Hash Table`,`Ordered Set`,`Heap (Priority Queue)` | Medium | Weekly Contest 390 |
| 3093 | [Longest Common Suffix Queries](/solution/3000-3099/3093.Longest%20Common%20Suffix%20Queries/README_EN.md) | `Trie`,`Array`,`String` | Hard | Weekly Contest 390 |
## Copyright

File diff suppressed because one or more lines are too long

View File

@ -249,17 +249,17 @@
- [2993.发生在周五的交易 I](/database-solution/2900-2999/2993.Friday%20Purchases%20I/README.md)
- [2994.发生在周五的交易 II](/database-solution/2900-2999/2994.Friday%20Purchases%20II/README.md)
- [2995.观众变主播](/database-solution/2900-2999/2995.Viewers%20Turned%20Streamers/README.md)
- [3050.Pizza Toppings Cost Analysis](/database-solution/3000-3099/3050.Pizza%20Toppings%20Cost%20Analysis/README.md)
- [3051.Find Candidates for Data Scientist Position](/database-solution/3000-3099/3051.Find%20Candidates%20for%20Data%20Scientist%20Position/README.md)
- [3052.Maximize Items](/database-solution/3000-3099/3052.Maximize%20Items/README.md)
- [3053.Classifying Triangles by Lengths](/database-solution/3000-3099/3053.Classifying%20Triangles%20by%20Lengths/README.md)
- [3054.Binary Tree Nodes](/database-solution/3000-3099/3054.Binary%20Tree%20Nodes/README.md)
- [3055.Top Percentile Fraud](/database-solution/3000-3099/3055.Top%20Percentile%20Fraud/README.md)
- [3056.Snaps Analysis](/database-solution/3000-3099/3056.Snaps%20Analysis/README.md)
- [3057.Employees Project Allocation](/database-solution/3000-3099/3057.Employees%20Project%20Allocation/README.md)
- [3058.Friends With No Mutual Friends](/database-solution/3000-3099/3058.Friends%20With%20No%20Mutual%20Friends/README.md)
- [3059.Find All Unique Email Domains](/database-solution/3000-3099/3059.Find%20All%20Unique%20Email%20Domains/README.md)
- [3050.披萨配料成本分析](/database-solution/3000-3099/3050.Pizza%20Toppings%20Cost%20Analysis/README.md)
- [3051.寻找数据科学家职位的候选人](/database-solution/3000-3099/3051.Find%20Candidates%20for%20Data%20Scientist%20Position/README.md)
- [3052.最大化商品](/database-solution/3000-3099/3052.Maximize%20Items/README.md)
- [3053.根据长度分类三角形](/database-solution/3000-3099/3053.Classifying%20Triangles%20by%20Lengths/README.md)
- [3054.二叉树节点](/database-solution/3000-3099/3054.Binary%20Tree%20Nodes/README.md)
- [3055.最高欺诈百分位数](/database-solution/3000-3099/3055.Top%20Percentile%20Fraud/README.md)
- [3056.快照分析](/database-solution/3000-3099/3056.Snaps%20Analysis/README.md)
- [3057.员工项目分配](/database-solution/3000-3099/3057.Employees%20Project%20Allocation/README.md)
- [3058.没有共同朋友的朋友](/database-solution/3000-3099/3058.Friends%20With%20No%20Mutual%20Friends/README.md)
- [3059.找到所有不同的邮件域名](/database-solution/3000-3099/3059.Find%20All%20Unique%20Email%20Domains/README.md)
- [3060.时间范围内的用户活动](/database-solution/3000-3099/3060.User%20Activities%20within%20Time%20Bounds/README.md)
- [3061.计算滞留雨水](/database-solution/3000-3099/3061.Calculate%20Trapping%20Rain%20Water/README.md)
- [3087.查找热门话题标签](/database-solution/3000-3099/3087.Find%20Trending%20Hashtags/README.md)
- [3089.Find Bursty Behavior](/database-solution/3000-3099/3089.Find%20Bursty%20Behavior/README.md)
- [3089.查找突发行为](/database-solution/3000-3099/3089.Find%20Bursty%20Behavior/README.md)

View File

@ -144,7 +144,7 @@ This work is licensed under a <a rel="license" href="http://creativecommons.org/
## 赛后估分网站
- https://lccn.lbao.site
如果你想在比赛结束后估算自己的积分变化,可以访问网站 [LeetCode Contest Rating Predictor](https://lccn.lbao.site/)。
## 往期竞赛
@ -179,7 +179,7 @@ For top 10 users (excluding LCCN users), your LeetCode ID will be colored orange
## Rating Predictor
Get your rating changes right after the completion of LeetCode contests, https://lccn.lbao.site
If you want to estimate your score changes after the contest ends, you can visit the website [LeetCode Contest Rating Predictor](https://lccn.lbao.site/).
## Past Contests