diff --git a/lcci/16.04.Tic-Tac-Toe/README.md b/lcci/16.04.Tic-Tac-Toe/README.md index e073f53647620..b8e03430eb2c5 100644 --- a/lcci/16.04.Tic-Tac-Toe/README.md +++ b/lcci/16.04.Tic-Tac-Toe/README.md @@ -77,7 +77,12 @@ class Solution: dg += v if i + j + 1 == n: udg += v - if abs(rows[i]) == n or abs(cols[j]) == n or abs(dg) == n or abs(udg) == n: + if ( + abs(rows[i]) == n + or abs(cols[j]) == n + or abs(dg) == n + or abs(udg) == n + ): return c return 'Pending' if has_empty_grid else 'Draw' ``` diff --git a/lcci/16.04.Tic-Tac-Toe/README_EN.md b/lcci/16.04.Tic-Tac-Toe/README_EN.md index 6cddbe56c249a..cc5a604512939 100644 --- a/lcci/16.04.Tic-Tac-Toe/README_EN.md +++ b/lcci/16.04.Tic-Tac-Toe/README_EN.md @@ -85,7 +85,12 @@ class Solution: dg += v if i + j + 1 == n: udg += v - if abs(rows[i]) == n or abs(cols[j]) == n or abs(dg) == n or abs(udg) == n: + if ( + abs(rows[i]) == n + or abs(cols[j]) == n + or abs(dg) == n + or abs(udg) == n + ): return c return 'Pending' if has_empty_grid else 'Draw' ``` diff --git a/solution/0000-0099/0002.Add Two Numbers/Solution.php b/solution/0000-0099/0002.Add Two Numbers/Solution.php index f5f14f9b7d0dd..83b4f8c8d023b 100644 --- a/solution/0000-0099/0002.Add Two Numbers/Solution.php +++ b/solution/0000-0099/0002.Add Two Numbers/Solution.php @@ -44,4 +44,4 @@ function addTwoNumbers($l1, $l2) { return $dummy->next; } -} +} \ No newline at end of file diff --git a/solution/0000-0099/0003.Longest Substring Without Repeating Characters/Solution.php b/solution/0000-0099/0003.Longest Substring Without Repeating Characters/Solution.php index e3d728856d3e9..1852d0018e3b2 100644 --- a/solution/0000-0099/0003.Longest Substring Without Repeating Characters/Solution.php +++ b/solution/0000-0099/0003.Longest Substring Without Repeating Characters/Solution.php @@ -21,4 +21,4 @@ function lengthOfLongestSubstring($s) { } return $max; } -} +} \ No newline at end of file diff --git a/solution/0100-0199/0100.Same Tree/Solution.php b/solution/0100-0199/0100.Same Tree/Solution.php index 6ef53da8152e7..73c9418c7f388 100644 --- a/solution/0100-0199/0100.Same Tree/Solution.php +++ b/solution/0100-0199/0100.Same Tree/Solution.php @@ -27,7 +27,6 @@ function isSameTree($p, $q) { if ($p->val != $q->val) { return false; } - return $this->isSameTree($p->left, $q->left) && - $this->isSameTree($p->right, $q->right); + return $this->isSameTree($p->left, $q->left) && $this->isSameTree($p->right, $q->right); } } \ No newline at end of file diff --git a/solution/0100-0199/0105.Construct Binary Tree from Preorder and Inorder Traversal/README.md b/solution/0100-0199/0105.Construct Binary Tree from Preorder and Inorder Traversal/README.md index a0d8d2c772a55..d232c6100b270 100644 --- a/solution/0100-0199/0105.Construct Binary Tree from Preorder and Inorder Traversal/README.md +++ b/solution/0100-0199/0105.Construct Binary Tree from Preorder and Inorder Traversal/README.md @@ -249,7 +249,7 @@ public: for (int i = 0; i < n; ++i) { d[inOrder[i]].push_back(i); } - function(int, int, int)> dfs = [&](int i,int j, int n) -> vector { + function(int, int, int)> dfs = [&](int i, int j, int n) -> vector { vector ans; if (n <= 0) { ans.push_back(nullptr); diff --git a/solution/0100-0199/0105.Construct Binary Tree from Preorder and Inorder Traversal/README_EN.md b/solution/0100-0199/0105.Construct Binary Tree from Preorder and Inorder Traversal/README_EN.md index 1ce3f1c1e41df..adc1480ac4fd3 100644 --- a/solution/0100-0199/0105.Construct Binary Tree from Preorder and Inorder Traversal/README_EN.md +++ b/solution/0100-0199/0105.Construct Binary Tree from Preorder and Inorder Traversal/README_EN.md @@ -239,7 +239,7 @@ public: for (int i = 0; i < n; ++i) { d[inOrder[i]].push_back(i); } - function(int, int, int)> dfs = [&](int i,int j, int n) -> vector { + function(int, int, int)> dfs = [&](int i, int j, int n) -> vector { vector ans; if (n <= 0) { ans.push_back(nullptr); diff --git a/solution/0100-0199/0175.Combine Two Tables/README_EN.md b/solution/0100-0199/0175.Combine Two Tables/README_EN.md index 690d28b9cbf2d..9dea3d587ccac 100644 --- a/solution/0100-0199/0175.Combine Two Tables/README_EN.md +++ b/solution/0100-0199/0175.Combine Two Tables/README_EN.md @@ -102,7 +102,6 @@ def combine_two_tables(person: pd.DataFrame, address: pd.DataFrame) -> pd.DataFr return pd.merge(left=person, right=address, how="left", on="personId")[ ["firstName", "lastName", "city", "state"] ] - ``` diff --git a/solution/0100-0199/0181.Employees Earning More Than Their Managers/README_EN.md b/solution/0100-0199/0181.Employees Earning More Than Their Managers/README_EN.md index 82ce7348eeaf1..d22ed817ff531 100644 --- a/solution/0100-0199/0181.Employees Earning More Than Their Managers/README_EN.md +++ b/solution/0100-0199/0181.Employees Earning More Than Their Managers/README_EN.md @@ -88,7 +88,6 @@ def find_employees(employee: pd.DataFrame) -> pd.DataFrame: emp = df[df["salary_x"] > df["salary_y"]]["name_x"] return pd.DataFrame({"Employee": emp}) - ``` diff --git a/solution/0100-0199/0185.Department Top Three Salaries/README.md b/solution/0100-0199/0185.Department Top Three Salaries/README.md index 814688a39ccab..95ff8e9eba82d 100644 --- a/solution/0100-0199/0185.Department Top Three Salaries/README.md +++ b/solution/0100-0199/0185.Department Top Three Salaries/README.md @@ -162,7 +162,6 @@ def top_three_salaries( return employee[employee["salary"] >= employee["cutoff"]].rename( columns={"name": "Employee", "salary": "Salary"} )[["Department", "Employee", "Salary"]] - ``` diff --git a/solution/0100-0199/0185.Department Top Three Salaries/README_EN.md b/solution/0100-0199/0185.Department Top Three Salaries/README_EN.md index 7923dd975a7d1..823a0a43c156b 100644 --- a/solution/0100-0199/0185.Department Top Three Salaries/README_EN.md +++ b/solution/0100-0199/0185.Department Top Three Salaries/README_EN.md @@ -158,7 +158,6 @@ def top_three_salaries( return employee[employee["salary"] >= employee["cutoff"]].rename( columns={"name": "Employee", "salary": "Salary"} )[["Department", "Employee", "Salary"]] - ``` diff --git a/solution/0100-0199/0196.Delete Duplicate Emails/README.md b/solution/0100-0199/0196.Delete Duplicate Emails/README.md index f9c770024b842..120175eb21ad7 100644 --- a/solution/0100-0199/0196.Delete Duplicate Emails/README.md +++ b/solution/0100-0199/0196.Delete Duplicate Emails/README.md @@ -109,7 +109,6 @@ def delete_duplicate_emails(person: pd.DataFrame) -> None: person.sort_values(by="id", ascending=True, inplace=True) # Drop the duplicates based on email. person.drop_duplicates(subset="email", keep="first", inplace=True) - ``` diff --git a/solution/0100-0199/0196.Delete Duplicate Emails/README_EN.md b/solution/0100-0199/0196.Delete Duplicate Emails/README_EN.md index 5a7948ae8cedc..d9e74cf4b59e6 100644 --- a/solution/0100-0199/0196.Delete Duplicate Emails/README_EN.md +++ b/solution/0100-0199/0196.Delete Duplicate Emails/README_EN.md @@ -105,7 +105,6 @@ def delete_duplicate_emails(person: pd.DataFrame) -> None: person.sort_values(by="id", ascending=True, inplace=True) # Drop the duplicates based on email. person.drop_duplicates(subset="email", keep="first", inplace=True) - ``` diff --git a/solution/0100-0199/0197.Rising Temperature/README.md b/solution/0100-0199/0197.Rising Temperature/README.md index bd685ffa0736d..05718f04ece75 100644 --- a/solution/0100-0199/0197.Rising Temperature/README.md +++ b/solution/0100-0199/0197.Rising Temperature/README.md @@ -98,7 +98,6 @@ def rising_temperature(weather: pd.DataFrame) -> pd.DataFrame: return weather[ (weather.temperature.diff() > 0) & (weather.recordDate.diff().dt.days == 1) ][["id"]] - ``` diff --git a/solution/0100-0199/0197.Rising Temperature/README_EN.md b/solution/0100-0199/0197.Rising Temperature/README_EN.md index 97c3c75a8fabc..1c77ae9dabd14 100644 --- a/solution/0100-0199/0197.Rising Temperature/README_EN.md +++ b/solution/0100-0199/0197.Rising Temperature/README_EN.md @@ -91,7 +91,6 @@ def rising_temperature(weather: pd.DataFrame) -> pd.DataFrame: return weather[ (weather.temperature.diff() > 0) & (weather.recordDate.diff().dt.days == 1) ][["id"]] - ``` diff --git a/solution/0200-0299/0219.Contains Duplicate II/Solution.php b/solution/0200-0299/0219.Contains Duplicate II/Solution.php index 5ed5e5fb9c403..05102bd518d4d 100644 --- a/solution/0200-0299/0219.Contains Duplicate II/Solution.php +++ b/solution/0200-0299/0219.Contains Duplicate II/Solution.php @@ -8,10 +8,7 @@ function containsNearbyDuplicate($nums, $k) { $hashtable = []; for ($i = 0; $i < count($nums); $i++) { $tmp = $nums[$i]; - if ( - array_key_exists($tmp, $hashtable) && - $k >= $i - $hashtable[$tmp] - ) { + if (array_key_exists($tmp, $hashtable) && $k >= $i - $hashtable[$tmp]) { return true; } $hashtable[$tmp] = $i; diff --git a/solution/0200-0299/0262.Trips and Users/README.md b/solution/0200-0299/0262.Trips and Users/README.md index c25fa534548f1..1c345dfe16742 100644 --- a/solution/0200-0299/0262.Trips and Users/README.md +++ b/solution/0200-0299/0262.Trips and Users/README.md @@ -186,7 +186,6 @@ def trips_and_users(trips: pd.DataFrame, users: pd.DataFrame) -> pd.DataFrame: # 4) calculating the ratio df["Cancellation Rate"] = (df["total_cancelled"] / df["total"]).round(2) return df[["Day", "Cancellation Rate"]] - ``` diff --git a/solution/0200-0299/0262.Trips and Users/README_EN.md b/solution/0200-0299/0262.Trips and Users/README_EN.md index 87762ba27cc4b..9a03b62d6876a 100644 --- a/solution/0200-0299/0262.Trips and Users/README_EN.md +++ b/solution/0200-0299/0262.Trips and Users/README_EN.md @@ -173,7 +173,6 @@ def trips_and_users(trips: pd.DataFrame, users: pd.DataFrame) -> pd.DataFrame: # 4) calculating the ratio df["Cancellation Rate"] = (df["total_cancelled"] / df["total"]).round(2) return df[["Day", "Cancellation Rate"]] - ``` diff --git a/solution/0300-0399/0305.Number of Islands II/README.md b/solution/0300-0399/0305.Number of Islands II/README.md index eed6773192a6c..594451a8d1ef5 100644 --- a/solution/0300-0399/0305.Number of Islands II/README.md +++ b/solution/0300-0399/0305.Number of Islands II/README.md @@ -108,7 +108,12 @@ class Solution: cnt += 1 for a, b in pairwise(dirs): x, y = i + a, j + b - if 0 <= x < m and 0 <= y < n and grid[x][y] and uf.union(i * n + j, x * n + y): + if ( + 0 <= x < m + and 0 <= y < n + and grid[x][y] + and uf.union(i * n + j, x * n + y) + ): cnt -= 1 ans.append(cnt) return ans diff --git a/solution/0300-0399/0305.Number of Islands II/README_EN.md b/solution/0300-0399/0305.Number of Islands II/README_EN.md index 083a38e15839d..bf2258fd6956b 100644 --- a/solution/0300-0399/0305.Number of Islands II/README_EN.md +++ b/solution/0300-0399/0305.Number of Islands II/README_EN.md @@ -100,7 +100,12 @@ class Solution: cnt += 1 for a, b in pairwise(dirs): x, y = i + a, j + b - if 0 <= x < m and 0 <= y < n and grid[x][y] and uf.union(i * n + j, x * n + y): + if ( + 0 <= x < m + and 0 <= y < n + and grid[x][y] + and uf.union(i * n + j, x * n + y) + ): cnt -= 1 ans.append(cnt) return ans diff --git a/solution/0300-0399/0307.Range Sum Query - Mutable/README.md b/solution/0300-0399/0307.Range Sum Query - Mutable/README.md index f71f115889f65..8413741c05ec6 100644 --- a/solution/0300-0399/0307.Range Sum Query - Mutable/README.md +++ b/solution/0300-0399/0307.Range Sum Query - Mutable/README.md @@ -559,91 +559,90 @@ func (t *NumArray) SumRange(left int, right int) int { ```go type Node struct { - l, r, v int + l, r, v int } type SegmentTree struct { - tr []Node - nums []int + tr []Node + nums []int } func newSegmentTree(nums []int) *SegmentTree { - n := len(nums) - tr := make([]Node, n<<2) - for i := range tr { - tr[i] = Node{} - } - tree := &SegmentTree{ - tr: tr, - nums: nums, - } - tree.build(1, 1, n) - return tree + n := len(nums) + tr := make([]Node, n<<2) + for i := range tr { + tr[i] = Node{} + } + tree := &SegmentTree{ + tr: tr, + nums: nums, + } + tree.build(1, 1, n) + return tree } func (tree *SegmentTree) build(u, l, r int) { - tree.tr[u].l, tree.tr[u].r = l, r - if l == r { - tree.tr[u].v = tree.nums[l-1] - return - } - mid := (l + r) >> 1 - tree.build(u<<1, l, mid) - tree.build(u<<1|1, mid+1, r) - tree.pushup(u) + tree.tr[u].l, tree.tr[u].r = l, r + if l == r { + tree.tr[u].v = tree.nums[l-1] + return + } + mid := (l + r) >> 1 + tree.build(u<<1, l, mid) + tree.build(u<<1|1, mid+1, r) + tree.pushup(u) } func (tree *SegmentTree) modify(u, x, v int) { - if tree.tr[u].l == x && tree.tr[u].r == x { - tree.tr[u].v = v - return - } - mid := (tree.tr[u].l + tree.tr[u].r) >> 1 - if x <= mid { - tree.modify(u<<1, x, v) - } else { - tree.modify(u<<1|1, x, v) - } - tree.pushup(u) + if tree.tr[u].l == x && tree.tr[u].r == x { + tree.tr[u].v = v + return + } + mid := (tree.tr[u].l + tree.tr[u].r) >> 1 + if x <= mid { + tree.modify(u<<1, x, v) + } else { + tree.modify(u<<1|1, x, v) + } + tree.pushup(u) } func (tree *SegmentTree) query(u, l, r int) (v int) { - if tree.tr[u].l >= l && tree.tr[u].r <= r { - return tree.tr[u].v - } - mid := (tree.tr[u].l + tree.tr[u].r) >> 1 - if l <= mid { - v += tree.query(u<<1, l, r) - } - if r > mid { - v += tree.query(u<<1|1, l, r) - } - return v + if tree.tr[u].l >= l && tree.tr[u].r <= r { + return tree.tr[u].v + } + mid := (tree.tr[u].l + tree.tr[u].r) >> 1 + if l <= mid { + v += tree.query(u<<1, l, r) + } + if r > mid { + v += tree.query(u<<1|1, l, r) + } + return v } func (tree *SegmentTree) pushup(u int) { - tree.tr[u].v = tree.tr[u<<1].v + tree.tr[u<<1|1].v + tree.tr[u].v = tree.tr[u<<1].v + tree.tr[u<<1|1].v } type NumArray struct { - tree *SegmentTree + tree *SegmentTree } func Constructor(nums []int) NumArray { - return NumArray{ - tree: newSegmentTree(nums), - } + return NumArray{ + tree: newSegmentTree(nums), + } } func (this *NumArray) Update(index int, val int) { - this.tree.modify(1, index+1, val) + this.tree.modify(1, index+1, val) } func (this *NumArray) SumRange(left int, right int) int { - return this.tree.query(1, left+1, right+1) + return this.tree.query(1, left+1, right+1) } - /** * Your NumArray object will be instantiated and called as such: * obj := Constructor(nums); diff --git a/solution/0300-0399/0307.Range Sum Query - Mutable/README_EN.md b/solution/0300-0399/0307.Range Sum Query - Mutable/README_EN.md index 2d0dff3e50b9e..864210d224a13 100644 --- a/solution/0300-0399/0307.Range Sum Query - Mutable/README_EN.md +++ b/solution/0300-0399/0307.Range Sum Query - Mutable/README_EN.md @@ -521,91 +521,90 @@ func (t *NumArray) SumRange(left int, right int) int { ```go type Node struct { - l, r, v int + l, r, v int } type SegmentTree struct { - tr []Node - nums []int + tr []Node + nums []int } func newSegmentTree(nums []int) *SegmentTree { - n := len(nums) - tr := make([]Node, n<<2) - for i := range tr { - tr[i] = Node{} - } - tree := &SegmentTree{ - tr: tr, - nums: nums, - } - tree.build(1, 1, n) - return tree + n := len(nums) + tr := make([]Node, n<<2) + for i := range tr { + tr[i] = Node{} + } + tree := &SegmentTree{ + tr: tr, + nums: nums, + } + tree.build(1, 1, n) + return tree } func (tree *SegmentTree) build(u, l, r int) { - tree.tr[u].l, tree.tr[u].r = l, r - if l == r { - tree.tr[u].v = tree.nums[l-1] - return - } - mid := (l + r) >> 1 - tree.build(u<<1, l, mid) - tree.build(u<<1|1, mid+1, r) - tree.pushup(u) + tree.tr[u].l, tree.tr[u].r = l, r + if l == r { + tree.tr[u].v = tree.nums[l-1] + return + } + mid := (l + r) >> 1 + tree.build(u<<1, l, mid) + tree.build(u<<1|1, mid+1, r) + tree.pushup(u) } func (tree *SegmentTree) modify(u, x, v int) { - if tree.tr[u].l == x && tree.tr[u].r == x { - tree.tr[u].v = v - return - } - mid := (tree.tr[u].l + tree.tr[u].r) >> 1 - if x <= mid { - tree.modify(u<<1, x, v) - } else { - tree.modify(u<<1|1, x, v) - } - tree.pushup(u) + if tree.tr[u].l == x && tree.tr[u].r == x { + tree.tr[u].v = v + return + } + mid := (tree.tr[u].l + tree.tr[u].r) >> 1 + if x <= mid { + tree.modify(u<<1, x, v) + } else { + tree.modify(u<<1|1, x, v) + } + tree.pushup(u) } func (tree *SegmentTree) query(u, l, r int) (v int) { - if tree.tr[u].l >= l && tree.tr[u].r <= r { - return tree.tr[u].v - } - mid := (tree.tr[u].l + tree.tr[u].r) >> 1 - if l <= mid { - v += tree.query(u<<1, l, r) - } - if r > mid { - v += tree.query(u<<1|1, l, r) - } - return v + if tree.tr[u].l >= l && tree.tr[u].r <= r { + return tree.tr[u].v + } + mid := (tree.tr[u].l + tree.tr[u].r) >> 1 + if l <= mid { + v += tree.query(u<<1, l, r) + } + if r > mid { + v += tree.query(u<<1|1, l, r) + } + return v } func (tree *SegmentTree) pushup(u int) { - tree.tr[u].v = tree.tr[u<<1].v + tree.tr[u<<1|1].v + tree.tr[u].v = tree.tr[u<<1].v + tree.tr[u<<1|1].v } type NumArray struct { - tree *SegmentTree + tree *SegmentTree } func Constructor(nums []int) NumArray { - return NumArray{ - tree: newSegmentTree(nums), - } + return NumArray{ + tree: newSegmentTree(nums), + } } func (this *NumArray) Update(index int, val int) { - this.tree.modify(1, index+1, val) + this.tree.modify(1, index+1, val) } func (this *NumArray) SumRange(left int, right int) int { - return this.tree.query(1, left+1, right+1) + return this.tree.query(1, left+1, right+1) } - /** * Your NumArray object will be instantiated and called as such: * obj := Constructor(nums); diff --git a/solution/0300-0399/0319.Bulb Switcher/README.md b/solution/0300-0399/0319.Bulb Switcher/README.md index 69c05d326e9f9..7e306837fdad0 100644 --- a/solution/0300-0399/0319.Bulb Switcher/README.md +++ b/solution/0300-0399/0319.Bulb Switcher/README.md @@ -66,7 +66,6 @@ class Solution: def bulbSwitch(self, n: int) -> int: return int(n ** (1 / 2)) - ``` ### **Java** diff --git a/solution/0300-0399/0319.Bulb Switcher/README_EN.md b/solution/0300-0399/0319.Bulb Switcher/README_EN.md index d0ae74a07b766..4722dcd00e3d2 100644 --- a/solution/0300-0399/0319.Bulb Switcher/README_EN.md +++ b/solution/0300-0399/0319.Bulb Switcher/README_EN.md @@ -53,7 +53,6 @@ So you should return 1 because there is only one bulb is on. class Solution: def bulbSwitch(self, n: int) -> int: return int(n ** (1 / 2)) - ``` ### **Java** diff --git a/solution/0300-0399/0332.Reconstruct Itinerary/README.md b/solution/0300-0399/0332.Reconstruct Itinerary/README.md index a84651a75af5e..527df6d785480 100644 --- a/solution/0300-0399/0332.Reconstruct Itinerary/README.md +++ b/solution/0300-0399/0332.Reconstruct Itinerary/README.md @@ -74,7 +74,6 @@ class Solution: dfs("JFK") return itinerary[::-1] - ``` ### **Java** diff --git a/solution/0300-0399/0332.Reconstruct Itinerary/README_EN.md b/solution/0300-0399/0332.Reconstruct Itinerary/README_EN.md index 2728db5195bf3..6a0a99388ddbf 100644 --- a/solution/0300-0399/0332.Reconstruct Itinerary/README_EN.md +++ b/solution/0300-0399/0332.Reconstruct Itinerary/README_EN.md @@ -66,7 +66,6 @@ class Solution: dfs("JFK") return itinerary[::-1] - ``` ### **Java** diff --git a/solution/0300-0399/0383.Ransom Note/Solution.php b/solution/0300-0399/0383.Ransom Note/Solution.php index 79004a27c5551..c3cc280db9ce3 100644 --- a/solution/0300-0399/0383.Ransom Note/Solution.php +++ b/solution/0300-0399/0383.Ransom Note/Solution.php @@ -10,10 +10,7 @@ function canConstruct($ransomNote, $magazine) { $hashtable[$arrM[$i]] += 1; } for ($j = 0; $j < strlen($ransomNote); $j++) { - if ( - !isset($hashtable[$ransomNote[$j]]) || - $hashtable[$ransomNote[$j]] == 0 - ) { + if (!isset($hashtable[$ransomNote[$j]]) || $hashtable[$ransomNote[$j]] == 0) { return false; } else { $hashtable[$ransomNote[$j]] -= 1; diff --git a/solution/0400-0499/0421.Maximum XOR of Two Numbers in an Array/README.md b/solution/0400-0499/0421.Maximum XOR of Two Numbers in an Array/README.md index b467ea592a31e..f5530e3293296 100644 --- a/solution/0400-0499/0421.Maximum XOR of Two Numbers in an Array/README.md +++ b/solution/0400-0499/0421.Maximum XOR of Two Numbers in an Array/README.md @@ -102,7 +102,6 @@ class Trie { private Trie[] children = new Trie[2]; public Trie() { - } public void insert(int x) { diff --git a/solution/0400-0499/0421.Maximum XOR of Two Numbers in an Array/README_EN.md b/solution/0400-0499/0421.Maximum XOR of Two Numbers in an Array/README_EN.md index a0cc9e7459cde..c7af2fa61f0e0 100644 --- a/solution/0400-0499/0421.Maximum XOR of Two Numbers in an Array/README_EN.md +++ b/solution/0400-0499/0421.Maximum XOR of Two Numbers in an Array/README_EN.md @@ -79,7 +79,6 @@ class Trie { private Trie[] children = new Trie[2]; public Trie() { - } public void insert(int x) { diff --git a/solution/0400-0499/0468.Validate IP Address/README.md b/solution/0400-0499/0468.Validate IP Address/README.md index c2ebcbd2ad29c..4efa8aa1f849c 100644 --- a/solution/0400-0499/0468.Validate IP Address/README.md +++ b/solution/0400-0499/0468.Validate IP Address/README.md @@ -92,7 +92,6 @@ class Solution: return "Neither" return "IPv6" return "Neither" - ``` ### **Java** diff --git a/solution/0400-0499/0468.Validate IP Address/README_EN.md b/solution/0400-0499/0468.Validate IP Address/README_EN.md index 89b91e1f10d6d..8eca659ddbc89 100644 --- a/solution/0400-0499/0468.Validate IP Address/README_EN.md +++ b/solution/0400-0499/0468.Validate IP Address/README_EN.md @@ -84,7 +84,6 @@ class Solution: return "Neither" return "IPv6" return "Neither" - ``` ### **Java** diff --git a/solution/0400-0499/0476.Number Complement/README.md b/solution/0400-0499/0476.Number Complement/README.md index 61af294e8da26..171900d247367 100644 --- a/solution/0400-0499/0476.Number Complement/README.md +++ b/solution/0400-0499/0476.Number Complement/README.md @@ -76,7 +76,6 @@ class Solution: class Solution: def findComplement(self, num: int) -> int: return num ^ (2 ** (len(bin(num)[2:])) - 1) - ``` ### **Java** diff --git a/solution/0400-0499/0476.Number Complement/README_EN.md b/solution/0400-0499/0476.Number Complement/README_EN.md index 2a17fdaa2c22f..58d49e2e1d152 100644 --- a/solution/0400-0499/0476.Number Complement/README_EN.md +++ b/solution/0400-0499/0476.Number Complement/README_EN.md @@ -64,7 +64,6 @@ class Solution: class Solution: def findComplement(self, num: int) -> int: return num ^ (2 ** (len(bin(num)[2:])) - 1) - ``` ### **Java** diff --git a/solution/0400-0499/0478.Generate Random Point in a Circle/README.md b/solution/0400-0499/0478.Generate Random Point in a Circle/README.md index 61cd82a7ea718..b4832cd455ca4 100644 --- a/solution/0400-0499/0478.Generate Random Point in a Circle/README.md +++ b/solution/0400-0499/0478.Generate Random Point in a Circle/README.md @@ -63,7 +63,6 @@ class Solution: x = self.x_center + length * math.cos(degree) y = self.y_center + length * math.sin(degree) return [x, y] - ``` ### **Java** diff --git a/solution/0400-0499/0478.Generate Random Point in a Circle/README_EN.md b/solution/0400-0499/0478.Generate Random Point in a Circle/README_EN.md index 9f5ef9486e426..47fdfa139f417 100644 --- a/solution/0400-0499/0478.Generate Random Point in a Circle/README_EN.md +++ b/solution/0400-0499/0478.Generate Random Point in a Circle/README_EN.md @@ -58,7 +58,6 @@ class Solution: x = self.x_center + length * math.cos(degree) y = self.y_center + length * math.sin(degree) return [x, y] - ``` ### **Java** diff --git a/solution/0500-0599/0511.Game Play Analysis I/README.md b/solution/0500-0599/0511.Game Play Analysis I/README.md index 32dac60720668..40d61c0867d12 100644 --- a/solution/0500-0599/0511.Game Play Analysis I/README.md +++ b/solution/0500-0599/0511.Game Play Analysis I/README.md @@ -81,7 +81,6 @@ def game_analysis(activity: pd.DataFrame) -> pd.DataFrame: .agg(first_login=("event_date", "min")) .reset_index() ) - ``` diff --git a/solution/0500-0599/0511.Game Play Analysis I/README_EN.md b/solution/0500-0599/0511.Game Play Analysis I/README_EN.md index 0780af95f1522..76aff9bc421c6 100644 --- a/solution/0500-0599/0511.Game Play Analysis I/README_EN.md +++ b/solution/0500-0599/0511.Game Play Analysis I/README_EN.md @@ -82,7 +82,6 @@ def game_analysis(activity: pd.DataFrame) -> pd.DataFrame: .agg(first_login=("event_date", "min")) .reset_index() ) - ``` diff --git a/solution/0500-0599/0550.Game Play Analysis IV/README.md b/solution/0500-0599/0550.Game Play Analysis IV/README.md index 0964a1fe0fd8b..b77e0ab6dbb53 100644 --- a/solution/0500-0599/0550.Game Play Analysis IV/README.md +++ b/solution/0500-0599/0550.Game Play Analysis IV/README.md @@ -122,7 +122,6 @@ def gameplay_analysis(activity: pd.DataFrame) -> pd.DataFrame: return pd.DataFrame( {"fraction": [round(len(activity_2nd_day) / activity.player_id.nunique(), 2)]} ) - ``` diff --git a/solution/0500-0599/0550.Game Play Analysis IV/README_EN.md b/solution/0500-0599/0550.Game Play Analysis IV/README_EN.md index 57134548853a8..024fb8a04e088 100644 --- a/solution/0500-0599/0550.Game Play Analysis IV/README_EN.md +++ b/solution/0500-0599/0550.Game Play Analysis IV/README_EN.md @@ -117,7 +117,6 @@ def gameplay_analysis(activity: pd.DataFrame) -> pd.DataFrame: return pd.DataFrame( {"fraction": [round(len(activity_2nd_day) / activity.player_id.nunique(), 2)]} ) - ``` diff --git a/solution/0500-0599/0570.Managers with at Least 5 Direct Reports/README.md b/solution/0500-0599/0570.Managers with at Least 5 Direct Reports/README.md index cdc9d52debeb3..ae4842949cb74 100644 --- a/solution/0500-0599/0570.Managers with at Least 5 Direct Reports/README.md +++ b/solution/0500-0599/0570.Managers with at Least 5 Direct Reports/README.md @@ -105,7 +105,6 @@ def find_managers(employee: pd.DataFrame) -> pd.DataFrame: result = result[["name"]] return result - ``` diff --git a/solution/0500-0599/0570.Managers with at Least 5 Direct Reports/README_EN.md b/solution/0500-0599/0570.Managers with at Least 5 Direct Reports/README_EN.md index 23cd07e5f4fa0..b0f12d8fe943e 100644 --- a/solution/0500-0599/0570.Managers with at Least 5 Direct Reports/README_EN.md +++ b/solution/0500-0599/0570.Managers with at Least 5 Direct Reports/README_EN.md @@ -101,7 +101,6 @@ def find_managers(employee: pd.DataFrame) -> pd.DataFrame: result = result[["name"]] return result - ``` diff --git a/solution/0600-0699/0679.24 Game/Solution.go b/solution/0600-0699/0679.24 Game/Solution.go index 2753061cdf404..a37dbc96efb7f 100644 --- a/solution/0600-0699/0679.24 Game/Solution.go +++ b/solution/0600-0699/0679.24 Game/Solution.go @@ -1,50 +1,50 @@ -func judgePoint24(cards []int) bool { - ops := [4]rune{'+', '-', '*', '/'} - nums := make([]float64, len(cards)) - for i, num := range cards { - nums[i] = float64(num) - } - var dfs func([]float64) bool - dfs = func(nums []float64) bool { - n := len(nums) - if n == 1 { - return math.Abs(nums[0]-24) < 1e-6 - } - ok := false - for i := 0; i < n; i++ { - for j := 0; j < n; j++ { - if i != j { - var nxt []float64 - for k := 0; k < n; k++ { - if k != i && k != j { - nxt = append(nxt, nums[k]) - } - } - for _, op := range ops { - switch op { - case '/': - if nums[j] == 0 { - continue - } - nxt = append(nxt, nums[i]/nums[j]) - case '*': - nxt = append(nxt, nums[i]*nums[j]) - case '+': - nxt = append(nxt, nums[i]+nums[j]) - case '-': - nxt = append(nxt, nums[i]-nums[j]) - } - ok = ok || dfs(nxt) - if ok { - return true - } - nxt = nxt[:len(nxt)-1] - } - } - } - } - return ok - } - - return dfs(nums) +func judgePoint24(cards []int) bool { + ops := [4]rune{'+', '-', '*', '/'} + nums := make([]float64, len(cards)) + for i, num := range cards { + nums[i] = float64(num) + } + var dfs func([]float64) bool + dfs = func(nums []float64) bool { + n := len(nums) + if n == 1 { + return math.Abs(nums[0]-24) < 1e-6 + } + ok := false + for i := 0; i < n; i++ { + for j := 0; j < n; j++ { + if i != j { + var nxt []float64 + for k := 0; k < n; k++ { + if k != i && k != j { + nxt = append(nxt, nums[k]) + } + } + for _, op := range ops { + switch op { + case '/': + if nums[j] == 0 { + continue + } + nxt = append(nxt, nums[i]/nums[j]) + case '*': + nxt = append(nxt, nums[i]*nums[j]) + case '+': + nxt = append(nxt, nums[i]+nums[j]) + case '-': + nxt = append(nxt, nums[i]-nums[j]) + } + ok = ok || dfs(nxt) + if ok { + return true + } + nxt = nxt[:len(nxt)-1] + } + } + } + } + return ok + } + + return dfs(nums) } \ No newline at end of file diff --git a/solution/0700-0799/0715.Range Module/README.md b/solution/0700-0799/0715.Range Module/README.md index 288955e3b34c9..496c9e6a7c642 100644 --- a/solution/0700-0799/0715.Range Module/README.md +++ b/solution/0700-0799/0715.Range Module/README.md @@ -151,6 +151,7 @@ class RangeModule: def removeRange(self, left: int, right: int) -> None: self.tree.modify(left, right - 1, -1) + # Your RangeModule object will be instantiated and called as such: # obj = RangeModule() # obj.addRange(left,right) diff --git a/solution/0700-0799/0715.Range Module/README_EN.md b/solution/0700-0799/0715.Range Module/README_EN.md index 578a4b8494cab..a43325df771ab 100644 --- a/solution/0700-0799/0715.Range Module/README_EN.md +++ b/solution/0700-0799/0715.Range Module/README_EN.md @@ -143,6 +143,7 @@ class RangeModule: def removeRange(self, left: int, right: int) -> None: self.tree.modify(left, right - 1, -1) + # Your RangeModule object will be instantiated and called as such: # obj = RangeModule() # obj.addRange(left,right) diff --git a/solution/0800-0899/0898.Bitwise ORs of Subarrays/README_EN.md b/solution/0800-0899/0898.Bitwise ORs of Subarrays/README_EN.md index 8cabaf183e7da..62b8166ceb66d 100644 --- a/solution/0800-0899/0898.Bitwise ORs of Subarrays/README_EN.md +++ b/solution/0800-0899/0898.Bitwise ORs of Subarrays/README_EN.md @@ -100,22 +100,22 @@ class Solution { ```cpp class Solution { -class Solution { -public: - int subarrayBitwiseORs(vector& arr) { - unordered_set s{{0}}; - unordered_set ans; - for (int& x : arr) { - unordered_set t{{x}}; - for (int y : s) { - t.insert(x | y); + class Solution { + public: + int subarrayBitwiseORs(vector& arr) { + unordered_set s{{0}}; + unordered_set ans; + for (int& x : arr) { + unordered_set t{{x}}; + for (int y : s) { + t.insert(x | y); + } + s = move(t); + ans.insert(s.begin(), s.end()); } - s = move(t); - ans.insert(s.begin(), s.end()); + return ans.size(); } - return ans.size(); - } -}; + }; ``` ### **Go** diff --git a/solution/0900-0999/0936.Stamping The Sequence/Solution.go b/solution/0900-0999/0936.Stamping The Sequence/Solution.go index f2f1d4b626655..95fb73a3ccf2e 100644 --- a/solution/0900-0999/0936.Stamping The Sequence/Solution.go +++ b/solution/0900-0999/0936.Stamping The Sequence/Solution.go @@ -1,47 +1,47 @@ -func movesToStamp(stamp string, target string) (ans []int) { - m, n := len(stamp), len(target) - indeg := make([]int, n-m+1) - for i := range indeg { - indeg[i] = m - } - g := make([][]int, n) - q := []int{} - for i := 0; i < n-m+1; i++ { - for j := range stamp { - if target[i+j] == stamp[j] { - indeg[i]-- - if indeg[i] == 0 { - q = append(q, i) - } - } else { - g[i+j] = append(g[i+j], i) - } - } - } - vis := make([]bool, n) - for len(q) > 0 { - i := q[0] - q = q[1:] - ans = append(ans, i) - for j := range stamp { - if !vis[i+j] { - vis[i+j] = true - for _, k := range g[i+j] { - indeg[k]-- - if indeg[k] == 0 { - q = append(q, k) - } - } - } - } - } - for _, v := range vis { - if !v { - return []int{} - } - } - for i, j := 0, len(ans)-1; i < j; i, j = i+1, j-1 { - ans[i], ans[j] = ans[j], ans[i] - } - return +func movesToStamp(stamp string, target string) (ans []int) { + m, n := len(stamp), len(target) + indeg := make([]int, n-m+1) + for i := range indeg { + indeg[i] = m + } + g := make([][]int, n) + q := []int{} + for i := 0; i < n-m+1; i++ { + for j := range stamp { + if target[i+j] == stamp[j] { + indeg[i]-- + if indeg[i] == 0 { + q = append(q, i) + } + } else { + g[i+j] = append(g[i+j], i) + } + } + } + vis := make([]bool, n) + for len(q) > 0 { + i := q[0] + q = q[1:] + ans = append(ans, i) + for j := range stamp { + if !vis[i+j] { + vis[i+j] = true + for _, k := range g[i+j] { + indeg[k]-- + if indeg[k] == 0 { + q = append(q, k) + } + } + } + } + } + for _, v := range vis { + if !v { + return []int{} + } + } + for i, j := 0, len(ans)-1; i < j; i, j = i+1, j-1 { + ans[i], ans[j] = ans[j], ans[i] + } + return } \ No newline at end of file diff --git a/solution/0900-0999/0995.Minimum Number of K Consecutive Bit Flips/Solution.go b/solution/0900-0999/0995.Minimum Number of K Consecutive Bit Flips/Solution.go index 1fe759d254354..69327feb0a57f 100644 --- a/solution/0900-0999/0995.Minimum Number of K Consecutive Bit Flips/Solution.go +++ b/solution/0900-0999/0995.Minimum Number of K Consecutive Bit Flips/Solution.go @@ -1,18 +1,18 @@ -func minKBitFlips(nums []int, k int) int { - n := len(nums) - d := make([]int, n+1) - ans, s := 0, 0 - for i, x := range nums { - s += d[i] - if s%2 == x%2 { - if i+k > n { - return -1 - } - d[i]++ - d[i+k]-- - s++ - ans++ - } - } - return ans +func minKBitFlips(nums []int, k int) int { + n := len(nums) + d := make([]int, n+1) + ans, s := 0, 0 + for i, x := range nums { + s += d[i] + if s%2 == x%2 { + if i+k > n { + return -1 + } + d[i]++ + d[i+k]-- + s++ + ans++ + } + } + return ans } \ No newline at end of file diff --git a/solution/1100-1199/1160.Find Words That Can Be Formed by Characters/Solution.php b/solution/1100-1199/1160.Find Words That Can Be Formed by Characters/Solution.php index 41d27722a93a6..0e52dd5dde1f5 100644 --- a/solution/1100-1199/1160.Find Words That Can Be Formed by Characters/Solution.php +++ b/solution/1100-1199/1160.Find Words That Can Be Formed by Characters/Solution.php @@ -13,10 +13,7 @@ function countCharacters($words, $chars) { $tmp = $hashtable; $sum += strlen($words[$j]); for ($k = 0; $k < strlen($words[$j]); $k++) { - if ( - !isset($tmp[$words[$j][$k]]) || - $tmp[$words[$j][$k]] === 0 - ) { + if (!isset($tmp[$words[$j][$k]]) || $tmp[$words[$j][$k]] === 0) { $sum -= strlen($words[$j]); break; } diff --git a/solution/1100-1199/1168.Optimize Water Distribution in a Village/README.md b/solution/1100-1199/1168.Optimize Water Distribution in a Village/README.md index 4db12a575d1e5..74c28b8954593 100644 --- a/solution/1100-1199/1168.Optimize Water Distribution in a Village/README.md +++ b/solution/1100-1199/1168.Optimize Water Distribution in a Village/README.md @@ -158,7 +158,7 @@ class Solution { public int minCostToSupplyWater(int n, int[] wells, int[][] pipes) { int[][] nums = Arrays.copyOf(pipes, pipes.length + n); for (int i = 0; i < n; i++) { - nums[pipes.length + i] = new int[]{0, i + 1, wells[i]}; + nums[pipes.length + i] = new int[] {0, i + 1, wells[i]}; } Arrays.sort(nums, (a, b) -> a[2] - b[2]); p = new int[n + 1]; diff --git a/solution/1100-1199/1168.Optimize Water Distribution in a Village/README_EN.md b/solution/1100-1199/1168.Optimize Water Distribution in a Village/README_EN.md index 4a1bb32d43068..e86f3ebb1a1c6 100644 --- a/solution/1100-1199/1168.Optimize Water Distribution in a Village/README_EN.md +++ b/solution/1100-1199/1168.Optimize Water Distribution in a Village/README_EN.md @@ -146,7 +146,7 @@ class Solution { public int minCostToSupplyWater(int n, int[] wells, int[][] pipes) { int[][] nums = Arrays.copyOf(pipes, pipes.length + n); for (int i = 0; i < n; i++) { - nums[pipes.length + i] = new int[]{0, i + 1, wells[i]}; + nums[pipes.length + i] = new int[] {0, i + 1, wells[i]}; } Arrays.sort(nums, (a, b) -> a[2] - b[2]); p = new int[n + 1]; diff --git a/solution/1300-1399/1322.Ads Performance/README.md b/solution/1300-1399/1322.Ads Performance/README.md index 3018165bd5d23..f4653b28a11cd 100644 --- a/solution/1300-1399/1322.Ads Performance/README.md +++ b/solution/1300-1399/1322.Ads Performance/README.md @@ -84,7 +84,7 @@ Ads 表: ```sql SELECT ad_id, - ROUND(IFNULL(SUM(action = 'Clicked') / SUM(action IN ('Clicked', 'Viewed')) * 100, 0), 2) AS ctr + ROUND(IFNULL(SUM(action = 'Clicked') / SUM(action IN('Clicked', 'Viewed')) * 100, 0), 2) AS ctr FROM Ads GROUP BY 1 ORDER BY 2 DESC, 1; diff --git a/solution/1300-1399/1322.Ads Performance/README_EN.md b/solution/1300-1399/1322.Ads Performance/README_EN.md index 5287b221ca5d1..739deba967f6b 100644 --- a/solution/1300-1399/1322.Ads Performance/README_EN.md +++ b/solution/1300-1399/1322.Ads Performance/README_EN.md @@ -77,7 +77,7 @@ Note that we do not care about Ignored Ads. ```sql SELECT ad_id, - ROUND(IFNULL(SUM(action = 'Clicked') / SUM(action IN ('Clicked', 'Viewed')) * 100, 0), 2) AS ctr + ROUND(IFNULL(SUM(action = 'Clicked') / SUM(action IN('Clicked', 'Viewed')) * 100, 0), 2) AS ctr FROM Ads GROUP BY 1 ORDER BY 2 DESC, 1; diff --git a/solution/1300-1399/1354.Construct Target Array With Multiple Sums/Solution.go b/solution/1300-1399/1354.Construct Target Array With Multiple Sums/Solution.go index 79fc1872a5c86..76c8f94cb021c 100644 --- a/solution/1300-1399/1354.Construct Target Array With Multiple Sums/Solution.go +++ b/solution/1300-1399/1354.Construct Target Array With Multiple Sums/Solution.go @@ -1,29 +1,29 @@ -func isPossible(target []int) bool { - pq := &hp{target} - s := 0 - for _, x := range target { - s += x - } - heap.Init(pq) - for target[0] > 1 { - mx := target[0] - t := s - mx - if t < 1 || mx-t < 1 { - return false - } - x := mx % t - if x == 0 { - x = t - } - target[0] = x - heap.Fix(pq, 0) - s = s - mx + x - } - return true -} - -type hp struct{ sort.IntSlice } - -func (h hp) Less(i, j int) bool { return h.IntSlice[i] > h.IntSlice[j] } -func (hp) Pop() (_ any) { return } +func isPossible(target []int) bool { + pq := &hp{target} + s := 0 + for _, x := range target { + s += x + } + heap.Init(pq) + for target[0] > 1 { + mx := target[0] + t := s - mx + if t < 1 || mx-t < 1 { + return false + } + x := mx % t + if x == 0 { + x = t + } + target[0] = x + heap.Fix(pq, 0) + s = s - mx + x + } + return true +} + +type hp struct{ sort.IntSlice } + +func (h hp) Less(i, j int) bool { return h.IntSlice[i] > h.IntSlice[j] } +func (hp) Pop() (_ any) { return } func (hp) Push(any) {} \ No newline at end of file diff --git a/solution/1400-1499/1402.Reducing Dishes/README_EN.md b/solution/1400-1499/1402.Reducing Dishes/README_EN.md index 0d2b50a72ab51..a1cbe86b289a9 100644 --- a/solution/1400-1499/1402.Reducing Dishes/README_EN.md +++ b/solution/1400-1499/1402.Reducing Dishes/README_EN.md @@ -75,7 +75,6 @@ class Solution: break ans += s return ans - ``` ### **Java** diff --git a/solution/1400-1499/1410.HTML Entity Parser/Solution.go b/solution/1400-1499/1410.HTML Entity Parser/Solution.go index ed3b22c1bf382..50b46e1e70a37 100644 --- a/solution/1400-1499/1410.HTML Entity Parser/Solution.go +++ b/solution/1400-1499/1410.HTML Entity Parser/Solution.go @@ -1,34 +1,34 @@ -func entityParser(text string) string { - d := map[string]string{ - """: "\"", - "'": "'", - "&": "&", - ">": ">", - "<": "<", - "⁄": "/", - } - var ans strings.Builder - i, n := 0, len(text) - - for i < n { - found := false - for l := 1; l < 8; l++ { - j := i + l - if j <= n { - t := text[i:j] - if val, ok := d[t]; ok { - ans.WriteString(val) - i = j - found = true - break - } - } - } - if !found { - ans.WriteByte(text[i]) - i++ - } - } - - return ans.String() +func entityParser(text string) string { + d := map[string]string{ + """: "\"", + "'": "'", + "&": "&", + ">": ">", + "<": "<", + "⁄": "/", + } + var ans strings.Builder + i, n := 0, len(text) + + for i < n { + found := false + for l := 1; l < 8; l++ { + j := i + l + if j <= n { + t := text[i:j] + if val, ok := d[t]; ok { + ans.WriteString(val) + i = j + found = true + break + } + } + } + if !found { + ans.WriteByte(text[i]) + i++ + } + } + + return ans.String() } \ No newline at end of file diff --git a/solution/1400-1499/1456.Maximum Number of Vowels in a Substring of Given Length/Solution.php b/solution/1400-1499/1456.Maximum Number of Vowels in a Substring of Given Length/Solution.php index a544e896c0eb5..ecdea8ddedb6e 100644 --- a/solution/1400-1499/1456.Maximum Number of Vowels in a Substring of Given Length/Solution.php +++ b/solution/1400-1499/1456.Maximum Number of Vowels in a Substring of Given Length/Solution.php @@ -5,11 +5,7 @@ class Solution { * @return Integer */ function isVowel($c) { - return $c === 'a' || - $c === 'e' || - $c === 'i' || - $c === 'o' || - $c === 'u'; + return $c === 'a' || $c === 'e' || $c === 'i' || $c === 'o' || $c === 'u'; } function maxVowels($s, $k) { $cnt = 0; diff --git a/solution/1400-1499/1462.Course Schedule IV/README.md b/solution/1400-1499/1462.Course Schedule IV/README.md index befaf208d4bbe..f69a501a1116f 100644 --- a/solution/1400-1499/1462.Course Schedule IV/README.md +++ b/solution/1400-1499/1462.Course Schedule IV/README.md @@ -221,8 +221,8 @@ public: f[p[0]][p[1]] = true; } for (int k = 0; k < n; ++k) { - for (int i = 0; i < n; ++ i) { - for (int j = 0; j < n; ++ j) { + for (int i = 0; i < n; ++i) { + for (int j = 0; j < n; ++j) { f[i][j] |= (f[i][k] && f[k][j]); } } diff --git a/solution/1400-1499/1462.Course Schedule IV/README_EN.md b/solution/1400-1499/1462.Course Schedule IV/README_EN.md index 5d65522262360..216284fb9a6db 100644 --- a/solution/1400-1499/1462.Course Schedule IV/README_EN.md +++ b/solution/1400-1499/1462.Course Schedule IV/README_EN.md @@ -178,8 +178,8 @@ public: f[p[0]][p[1]] = true; } for (int k = 0; k < n; ++k) { - for (int i = 0; i < n; ++ i) { - for (int j = 0; j < n; ++ j) { + for (int i = 0; i < n; ++i) { + for (int j = 0; j < n; ++j) { f[i][j] |= (f[i][k] && f[k][j]); } } diff --git a/solution/1500-1599/1531.String Compression II/README.md b/solution/1500-1599/1531.String Compression II/README.md index 50d0d2f9724e8..36c6d744dd493 100644 --- a/solution/1500-1599/1531.String Compression II/README.md +++ b/solution/1500-1599/1531.String Compression II/README.md @@ -94,7 +94,8 @@ class Solution { // the other letters. for (int j = i; j < s.length(); ++j) { maxFreq = Math.max(maxFreq, ++count[s.charAt(j)]); - dp[i][k] = Math.min(dp[i][k], getLength(maxFreq) + compression(s, j + 1, k - (j - i + 1 - maxFreq))); + dp[i][k] = Math.min( + dp[i][k], getLength(maxFreq) + compression(s, j + 1, k - (j - i + 1 - maxFreq))); } return dp[i][k]; } @@ -110,7 +111,7 @@ class Solution { if (maxFreq < 100) { return 3; // [1-9][0-9]c } - return 4; // [1-9][0-9][0-9]c + return 4; // [1-9][0-9][0-9]c } } ``` diff --git a/solution/1500-1599/1531.String Compression II/README_EN.md b/solution/1500-1599/1531.String Compression II/README_EN.md index d85e0b04ea683..ea953dfe3807a 100644 --- a/solution/1500-1599/1531.String Compression II/README_EN.md +++ b/solution/1500-1599/1531.String Compression II/README_EN.md @@ -87,7 +87,8 @@ class Solution { // the other letters. for (int j = i; j < s.length(); ++j) { maxFreq = Math.max(maxFreq, ++count[s.charAt(j)]); - dp[i][k] = Math.min(dp[i][k], getLength(maxFreq) + compression(s, j + 1, k - (j - i + 1 - maxFreq))); + dp[i][k] = Math.min( + dp[i][k], getLength(maxFreq) + compression(s, j + 1, k - (j - i + 1 - maxFreq))); } return dp[i][k]; } @@ -103,7 +104,7 @@ class Solution { if (maxFreq < 100) { return 3; // [1-9][0-9]c } - return 4; // [1-9][0-9][0-9]c + return 4; // [1-9][0-9][0-9]c } } ``` diff --git a/solution/1500-1599/1538.Guess the Majority in a Hidden Array/README.md b/solution/1500-1599/1538.Guess the Majority in a Hidden Array/README.md index 1bdf9e7616d7f..63d067e88716c 100644 --- a/solution/1500-1599/1538.Guess the Majority in a Hidden Array/README.md +++ b/solution/1500-1599/1538.Guess the Majority in a Hidden Array/README.md @@ -152,9 +152,10 @@ class Solution: * public: * // Compares 4 different elements in the array * // return 4 if the values of the 4 elements are the same (0 or 1). - * // return 2 if three elements have a value equal to 0 and one element has value equal to 1 or vice versa. - * // return 0 : if two element have a value equal to 0 and two elements have a value equal to 1. - * public int query(int a, int b, int c, int d); + * // return 2 if three elements have a value equal to 0 and one element has value equal to 1 or + * vice versa. + * // return 0 : if two element have a value equal to 0 and two elements have a value equal + * to 1. public int query(int a, int b, int c, int d); * * // Returns the length of the array * public int length(); @@ -224,7 +225,7 @@ class Solution { class Solution { public: - int guessMajority(ArrayReader &reader) { + int guessMajority(ArrayReader& reader) { int n = reader.length(); int x = reader.query(0, 1, 2, 3); int a = 1, b = 0; diff --git a/solution/1500-1599/1538.Guess the Majority in a Hidden Array/README_EN.md b/solution/1500-1599/1538.Guess the Majority in a Hidden Array/README_EN.md index 9fc0b5779c1d4..1ed29e47bbd7f 100644 --- a/solution/1500-1599/1538.Guess the Majority in a Hidden Array/README_EN.md +++ b/solution/1500-1599/1538.Guess the Majority in a Hidden Array/README_EN.md @@ -129,9 +129,10 @@ class Solution: * public: * // Compares 4 different elements in the array * // return 4 if the values of the 4 elements are the same (0 or 1). - * // return 2 if three elements have a value equal to 0 and one element has value equal to 1 or vice versa. - * // return 0 : if two element have a value equal to 0 and two elements have a value equal to 1. - * public int query(int a, int b, int c, int d); + * // return 2 if three elements have a value equal to 0 and one element has value equal to 1 or + * vice versa. + * // return 0 : if two element have a value equal to 0 and two elements have a value equal + * to 1. public int query(int a, int b, int c, int d); * * // Returns the length of the array * public int length(); @@ -201,7 +202,7 @@ class Solution { class Solution { public: - int guessMajority(ArrayReader &reader) { + int guessMajority(ArrayReader& reader) { int n = reader.length(); int x = reader.query(0, 1, 2, 3); int a = 1, b = 0; diff --git a/solution/1500-1599/1545.Find Kth Bit in Nth Binary String/Solution.go b/solution/1500-1599/1545.Find Kth Bit in Nth Binary String/Solution.go index 812a0dd923e2a..1cdb7092a4724 100644 --- a/solution/1500-1599/1545.Find Kth Bit in Nth Binary String/Solution.go +++ b/solution/1500-1599/1545.Find Kth Bit in Nth Binary String/Solution.go @@ -1,17 +1,17 @@ -func findKthBit(n int, k int) byte { - var dfs func(n, k int) int - dfs = func(n, k int) int { - if k == 1 { - return 0 - } - if k&(k-1) == 0 { - return 1 - } - m := 1 << n - if k*2 < m-1 { - return dfs(n-1, k) - } - return dfs(n-1, m-k) ^ 1 - } - return byte('0' + dfs(n, k)) +func findKthBit(n int, k int) byte { + var dfs func(n, k int) int + dfs = func(n, k int) int { + if k == 1 { + return 0 + } + if k&(k-1) == 0 { + return 1 + } + m := 1 << n + if k*2 < m-1 { + return dfs(n-1, k) + } + return dfs(n-1, m-k) ^ 1 + } + return byte('0' + dfs(n, k)) } \ No newline at end of file diff --git a/solution/1600-1699/1627.Graph Connectivity With Threshold/Solution.go b/solution/1600-1699/1627.Graph Connectivity With Threshold/Solution.go index d742d3725db2e..ce4d0a85dbb8c 100644 --- a/solution/1600-1699/1627.Graph Connectivity With Threshold/Solution.go +++ b/solution/1600-1699/1627.Graph Connectivity With Threshold/Solution.go @@ -1,49 +1,49 @@ -type unionFind struct { - p, size []int -} - -func newUnionFind(n int) *unionFind { - p := make([]int, n) - size := make([]int, n) - for i := range p { - p[i] = i - size[i] = 1 - } - return &unionFind{p, size} -} - -func (uf *unionFind) find(x int) int { - if uf.p[x] != x { - uf.p[x] = uf.find(uf.p[x]) - } - return uf.p[x] -} - -func (uf *unionFind) union(a, b int) bool { - pa, pb := uf.find(a), uf.find(b) - if pa == pb { - return false - } - if uf.size[pa] > uf.size[pb] { - uf.p[pb] = pa - uf.size[pa] += uf.size[pb] - } else { - uf.p[pa] = pb - uf.size[pb] += uf.size[pa] - } - return true -} - -func areConnected(n int, threshold int, queries [][]int) []bool { - uf := newUnionFind(n + 1) - for a := threshold + 1; a <= n; a++ { - for b := a + a; b <= n; b += a { - uf.union(a, b) - } - } - ans := make([]bool, len(queries)) - for i, q := range queries { - ans[i] = uf.find(q[0]) == uf.find(q[1]) - } - return ans +type unionFind struct { + p, size []int +} + +func newUnionFind(n int) *unionFind { + p := make([]int, n) + size := make([]int, n) + for i := range p { + p[i] = i + size[i] = 1 + } + return &unionFind{p, size} +} + +func (uf *unionFind) find(x int) int { + if uf.p[x] != x { + uf.p[x] = uf.find(uf.p[x]) + } + return uf.p[x] +} + +func (uf *unionFind) union(a, b int) bool { + pa, pb := uf.find(a), uf.find(b) + if pa == pb { + return false + } + if uf.size[pa] > uf.size[pb] { + uf.p[pb] = pa + uf.size[pa] += uf.size[pb] + } else { + uf.p[pa] = pb + uf.size[pb] += uf.size[pa] + } + return true +} + +func areConnected(n int, threshold int, queries [][]int) []bool { + uf := newUnionFind(n + 1) + for a := threshold + 1; a <= n; a++ { + for b := a + a; b <= n; b += a { + uf.union(a, b) + } + } + ans := make([]bool, len(queries)) + for i, q := range queries { + ans[i] = uf.find(q[0]) == uf.find(q[1]) + } + return ans } \ No newline at end of file diff --git a/solution/1600-1699/1631.Path With Minimum Effort/README.md b/solution/1600-1699/1631.Path With Minimum Effort/README.md index 738627548a83b..941c1f824379a 100644 --- a/solution/1600-1699/1631.Path With Minimum Effort/README.md +++ b/solution/1600-1699/1631.Path With Minimum Effort/README.md @@ -293,7 +293,8 @@ class Solution { } for (int k = 0; k < 4; ++k) { int x = i + dirs[k], y = j + dirs[k + 1]; - if (x >= 0 && x < m && y >= 0 && y < n && !vis[x][y] && Math.abs(heights[x][y] - heights[i][j]) <= h) { + if (x >= 0 && x < m && y >= 0 && y < n && !vis[x][y] + && Math.abs(heights[x][y] - heights[i][j]) <= h) { q.add(new int[] {x, y}); vis[x][y] = true; } diff --git a/solution/1600-1699/1631.Path With Minimum Effort/README_EN.md b/solution/1600-1699/1631.Path With Minimum Effort/README_EN.md index 7ce077338d4c9..f23a28223908d 100644 --- a/solution/1600-1699/1631.Path With Minimum Effort/README_EN.md +++ b/solution/1600-1699/1631.Path With Minimum Effort/README_EN.md @@ -283,7 +283,8 @@ class Solution { } for (int k = 0; k < 4; ++k) { int x = i + dirs[k], y = j + dirs[k + 1]; - if (x >= 0 && x < m && y >= 0 && y < n && !vis[x][y] && Math.abs(heights[x][y] - heights[i][j]) <= h) { + if (x >= 0 && x < m && y >= 0 && y < n && !vis[x][y] + && Math.abs(heights[x][y] - heights[i][j]) <= h) { q.add(new int[] {x, y}); vis[x][y] = true; } diff --git a/solution/1700-1799/1724.Checking Existence of Edge Length Limited Paths II/Solution.go b/solution/1700-1799/1724.Checking Existence of Edge Length Limited Paths II/Solution.go index 2d716c5bf038c..c4feb5b47c10f 100644 --- a/solution/1700-1799/1724.Checking Existence of Edge Length Limited Paths II/Solution.go +++ b/solution/1700-1799/1724.Checking Existence of Edge Length Limited Paths II/Solution.go @@ -1,80 +1,80 @@ -type PersistentUnionFind struct { - rank []int - parent []int - version []int -} - -func NewPersistentUnionFind(n int) *PersistentUnionFind { - rank := make([]int, n) - parent := make([]int, n) - version := make([]int, n) - - for i := 0; i < n; i++ { - parent[i] = i - } - - return &PersistentUnionFind{ - rank: rank, - parent: parent, - version: version, - } -} - -func (uf *PersistentUnionFind) find(x int, t int) int { - if uf.parent[x] == x || uf.version[x] >= t { - return x - } - return uf.find(uf.parent[x], t) -} - -func (uf *PersistentUnionFind) union(a, b, t int) bool { - pa := uf.find(a, int(^uint(0)>>1)) - pb := uf.find(b, int(^uint(0)>>1)) - - if pa == pb { - return false - } - - if uf.rank[pa] > uf.rank[pb] { - uf.version[pb] = t - uf.parent[pb] = pa - } else { - uf.version[pa] = t - uf.parent[pa] = pb - if uf.rank[pa] == uf.rank[pb] { - uf.rank[pb]++ - } - } - - return true -} - -type DistanceLimitedPathsExist struct { - puf *PersistentUnionFind -} - -func Constructor(n int, edgeList [][]int) DistanceLimitedPathsExist { - sort.Slice(edgeList, func(i, j int) bool { - return edgeList[i][2] < edgeList[j][2] - }) - - puf := NewPersistentUnionFind(n) - - for _, edge := range edgeList { - puf.union(edge[0], edge[1], edge[2]) - } - - return DistanceLimitedPathsExist{ - puf: puf, - } -} - -func (dle *DistanceLimitedPathsExist) Query(p, q, limit int) bool { - return dle.puf.find(p, limit) == dle.puf.find(q, limit) -} - -/** - * Your DistanceLimitedPathsExist object will be instantiated and called as such: - * obj := Constructor(n, edgeList); - * param_1 := obj.Query(p,q,limit); +type PersistentUnionFind struct { + rank []int + parent []int + version []int +} + +func NewPersistentUnionFind(n int) *PersistentUnionFind { + rank := make([]int, n) + parent := make([]int, n) + version := make([]int, n) + + for i := 0; i < n; i++ { + parent[i] = i + } + + return &PersistentUnionFind{ + rank: rank, + parent: parent, + version: version, + } +} + +func (uf *PersistentUnionFind) find(x int, t int) int { + if uf.parent[x] == x || uf.version[x] >= t { + return x + } + return uf.find(uf.parent[x], t) +} + +func (uf *PersistentUnionFind) union(a, b, t int) bool { + pa := uf.find(a, int(^uint(0)>>1)) + pb := uf.find(b, int(^uint(0)>>1)) + + if pa == pb { + return false + } + + if uf.rank[pa] > uf.rank[pb] { + uf.version[pb] = t + uf.parent[pb] = pa + } else { + uf.version[pa] = t + uf.parent[pa] = pb + if uf.rank[pa] == uf.rank[pb] { + uf.rank[pb]++ + } + } + + return true +} + +type DistanceLimitedPathsExist struct { + puf *PersistentUnionFind +} + +func Constructor(n int, edgeList [][]int) DistanceLimitedPathsExist { + sort.Slice(edgeList, func(i, j int) bool { + return edgeList[i][2] < edgeList[j][2] + }) + + puf := NewPersistentUnionFind(n) + + for _, edge := range edgeList { + puf.union(edge[0], edge[1], edge[2]) + } + + return DistanceLimitedPathsExist{ + puf: puf, + } +} + +func (dle *DistanceLimitedPathsExist) Query(p, q, limit int) bool { + return dle.puf.find(p, limit) == dle.puf.find(q, limit) +} + +/** + * Your DistanceLimitedPathsExist object will be instantiated and called as such: + * obj := Constructor(n, edgeList); + * param_1 := obj.Query(p,q,limit); */ \ No newline at end of file diff --git a/solution/1700-1799/1728.Cat and Mouse II/README.md b/solution/1700-1799/1728.Cat and Mouse II/README.md index 5d62429fa9da2..caf1c7bbf5f59 100644 --- a/solution/1700-1799/1728.Cat and Mouse II/README.md +++ b/solution/1700-1799/1728.Cat and Mouse II/README.md @@ -175,7 +175,6 @@ class Solution: return True return dp(cat, mouse, 0) - ``` ### **Java** diff --git a/solution/1700-1799/1728.Cat and Mouse II/README_EN.md b/solution/1700-1799/1728.Cat and Mouse II/README_EN.md index beef115aeaae9..7a587affbb430 100644 --- a/solution/1700-1799/1728.Cat and Mouse II/README_EN.md +++ b/solution/1700-1799/1728.Cat and Mouse II/README_EN.md @@ -149,7 +149,6 @@ class Solution: return True return dp(cat, mouse, 0) - ``` ### **Java** diff --git a/solution/1800-1899/1842.Next Palindrome Using Same Digits/Solution.go b/solution/1800-1899/1842.Next Palindrome Using Same Digits/Solution.go index e9bc199395ddd..019f3e51869bd 100644 --- a/solution/1800-1899/1842.Next Palindrome Using Same Digits/Solution.go +++ b/solution/1800-1899/1842.Next Palindrome Using Same Digits/Solution.go @@ -1,31 +1,31 @@ -func nextPalindrome(num string) string { - nums := []byte(num) - n := len(nums) - if !nextPermutation(nums) { - return "" - } - for i := 0; i < n/2; i++ { - nums[n-1-i] = nums[i] - } - return string(nums) -} - -func nextPermutation(nums []byte) bool { - n := len(nums) / 2 - i := n - 2 - for i >= 0 && nums[i] >= nums[i+1] { - i-- - } - if i < 0 { - return false - } - j := n - 1 - for j >= 0 && nums[j] <= nums[i] { - j-- - } - nums[i], nums[j] = nums[j], nums[i] - for i, j = i+1, n-1; i < j; i, j = i+1, j-1 { - nums[i], nums[j] = nums[j], nums[i] - } - return true +func nextPalindrome(num string) string { + nums := []byte(num) + n := len(nums) + if !nextPermutation(nums) { + return "" + } + for i := 0; i < n/2; i++ { + nums[n-1-i] = nums[i] + } + return string(nums) +} + +func nextPermutation(nums []byte) bool { + n := len(nums) / 2 + i := n - 2 + for i >= 0 && nums[i] >= nums[i+1] { + i-- + } + if i < 0 { + return false + } + j := n - 1 + for j >= 0 && nums[j] <= nums[i] { + j-- + } + nums[i], nums[j] = nums[j], nums[i] + for i, j = i+1, n-1; i < j; i, j = i+1, j-1 { + nums[i], nums[j] = nums[j], nums[i] + } + return true } \ No newline at end of file diff --git a/solution/1800-1899/1850.Minimum Adjacent Swaps to Reach the Kth Smallest Number/Solution.go b/solution/1800-1899/1850.Minimum Adjacent Swaps to Reach the Kth Smallest Number/Solution.go index 6513ca3afddd6..e5cf177722b92 100644 --- a/solution/1800-1899/1850.Minimum Adjacent Swaps to Reach the Kth Smallest Number/Solution.go +++ b/solution/1800-1899/1850.Minimum Adjacent Swaps to Reach the Kth Smallest Number/Solution.go @@ -1,47 +1,47 @@ -func getMinSwaps(num string, k int) (ans int) { - s := []byte(num) - for ; k > 0; k-- { - nextPermutation(s) - } - d := [10][]int{} - for i, c := range num { - j := int(c - '0') - d[j] = append(d[j], i) - } - idx := [10]int{} - n := len(s) - arr := make([]int, n) - for i, c := range s { - j := int(c - '0') - arr[i] = d[j][idx[j]] - idx[j]++ - } - for i := 0; i < n; i++ { - for j := 0; j < i; j++ { - if arr[j] > arr[i] { - ans++ - } - } - } - return -} - -func nextPermutation(nums []byte) bool { - n := len(nums) - i := n - 2 - for i >= 0 && nums[i] >= nums[i+1] { - i-- - } - if i < 0 { - return false - } - j := n - 1 - for j >= 0 && nums[j] <= nums[i] { - j-- - } - nums[i], nums[j] = nums[j], nums[i] - for i, j = i+1, n-1; i < j; i, j = i+1, j-1 { - nums[i], nums[j] = nums[j], nums[i] - } - return true +func getMinSwaps(num string, k int) (ans int) { + s := []byte(num) + for ; k > 0; k-- { + nextPermutation(s) + } + d := [10][]int{} + for i, c := range num { + j := int(c - '0') + d[j] = append(d[j], i) + } + idx := [10]int{} + n := len(s) + arr := make([]int, n) + for i, c := range s { + j := int(c - '0') + arr[i] = d[j][idx[j]] + idx[j]++ + } + for i := 0; i < n; i++ { + for j := 0; j < i; j++ { + if arr[j] > arr[i] { + ans++ + } + } + } + return +} + +func nextPermutation(nums []byte) bool { + n := len(nums) + i := n - 2 + for i >= 0 && nums[i] >= nums[i+1] { + i-- + } + if i < 0 { + return false + } + j := n - 1 + for j >= 0 && nums[j] <= nums[i] { + j-- + } + nums[i], nums[j] = nums[j], nums[i] + for i, j = i+1, n-1; i < j; i, j = i+1, j-1 { + nums[i], nums[j] = nums[j], nums[i] + } + return true } \ No newline at end of file diff --git a/solution/1800-1899/1862.Sum of Floored Pairs/Solution.go b/solution/1800-1899/1862.Sum of Floored Pairs/Solution.go index d9a12b38d81fc..2fc00bc938fd7 100644 --- a/solution/1800-1899/1862.Sum of Floored Pairs/Solution.go +++ b/solution/1800-1899/1862.Sum of Floored Pairs/Solution.go @@ -1,21 +1,21 @@ -func sumOfFlooredPairs(nums []int) (ans int) { - mx := slices.Max(nums) - cnt := make([]int, mx+1) - s := make([]int, mx+1) - for _, x := range nums { - cnt[x]++ - } - for i := 1; i <= mx; i++ { - s[i] = s[i-1] + cnt[i] - } - const mod int = 1e9 + 7 - for y := 1; y <= mx; y++ { - if cnt[y] > 0 { - for d := 1; d*y <= mx; d++ { - ans += d * cnt[y] * (s[min((d+1)*y-1, mx)] - s[d*y-1]) - ans %= mod - } - } - } - return +func sumOfFlooredPairs(nums []int) (ans int) { + mx := slices.Max(nums) + cnt := make([]int, mx+1) + s := make([]int, mx+1) + for _, x := range nums { + cnt[x]++ + } + for i := 1; i <= mx; i++ { + s[i] = s[i-1] + cnt[i] + } + const mod int = 1e9 + 7 + for y := 1; y <= mx; y++ { + if cnt[y] > 0 { + for d := 1; d*y <= mx; d++ { + ans += d * cnt[y] * (s[min((d+1)*y-1, mx)] - s[d*y-1]) + ans %= mod + } + } + } + return } \ No newline at end of file diff --git a/solution/1800-1899/1863.Sum of All Subset XOR Totals/Solution.go b/solution/1800-1899/1863.Sum of All Subset XOR Totals/Solution.go index 84693f1999b84..42f4a535d8583 100644 --- a/solution/1800-1899/1863.Sum of All Subset XOR Totals/Solution.go +++ b/solution/1800-1899/1863.Sum of All Subset XOR Totals/Solution.go @@ -1,14 +1,14 @@ -func subsetXORSum(nums []int) (ans int) { - n := len(nums) - var dfs func(int, int) - dfs = func(i, s int) { - if i >= n { - ans += s - return - } - dfs(i+1, s) - dfs(i+1, s^nums[i]) - } - dfs(0, 0) - return +func subsetXORSum(nums []int) (ans int) { + n := len(nums) + var dfs func(int, int) + dfs = func(i, s int) { + if i >= n { + ans += s + return + } + dfs(i+1, s) + dfs(i+1, s^nums[i]) + } + dfs(0, 0) + return } \ No newline at end of file diff --git a/solution/1800-1899/1871.Jump Game VII/Solution.go b/solution/1800-1899/1871.Jump Game VII/Solution.go index 6c0da16cdbfac..af28bead32626 100644 --- a/solution/1800-1899/1871.Jump Game VII/Solution.go +++ b/solution/1800-1899/1871.Jump Game VII/Solution.go @@ -1,18 +1,18 @@ -func canReach(s string, minJump int, maxJump int) bool { - n := len(s) - pre := make([]int, n+1) - pre[1] = 1 - f := make([]bool, n) - f[0] = true - for i := 1; i < n; i++ { - if s[i] == '0' { - l, r := max(0, i-maxJump), i-minJump - f[i] = l <= r && pre[r+1]-pre[l] > 0 - } - pre[i+1] = pre[i] - if f[i] { - pre[i+1]++ - } - } - return f[n-1] +func canReach(s string, minJump int, maxJump int) bool { + n := len(s) + pre := make([]int, n+1) + pre[1] = 1 + f := make([]bool, n) + f[0] = true + for i := 1; i < n; i++ { + if s[i] == '0' { + l, r := max(0, i-maxJump), i-minJump + f[i] = l <= r && pre[r+1]-pre[l] > 0 + } + pre[i+1] = pre[i] + if f[i] { + pre[i+1]++ + } + } + return f[n-1] } \ No newline at end of file diff --git a/solution/1800-1899/1872.Stone Game VIII/Solution.go b/solution/1800-1899/1872.Stone Game VIII/Solution.go index 97ee65b8dfb3a..60c1522f312fb 100644 --- a/solution/1800-1899/1872.Stone Game VIII/Solution.go +++ b/solution/1800-1899/1872.Stone Game VIII/Solution.go @@ -1,11 +1,11 @@ -func stoneGameVIII(stones []int) int { - n := len(stones) - for i := 1; i < n; i++ { - stones[i] += stones[i-1] - } - f := stones[n-1] - for i := n - 2; i > 0; i-- { - f = max(f, stones[i]-f) - } - return f +func stoneGameVIII(stones []int) int { + n := len(stones) + for i := 1; i < n; i++ { + stones[i] += stones[i-1] + } + f := stones[n-1] + for i := n - 2; i > 0; i-- { + f = max(f, stones[i]-f) + } + return f } \ No newline at end of file diff --git a/solution/1800-1899/1876.Substrings of Size Three with Distinct Characters/Solution.php b/solution/1800-1899/1876.Substrings of Size Three with Distinct Characters/Solution.php index 88feb97833e92..a6cfa9b724911 100644 --- a/solution/1800-1899/1876.Substrings of Size Three with Distinct Characters/Solution.php +++ b/solution/1800-1899/1876.Substrings of Size Three with Distinct Characters/Solution.php @@ -6,11 +6,7 @@ class Solution { function countGoodSubstrings($s) { $cnt = 0; for ($i = 0; $i < strlen($s) - 2; $i++) { - if ( - $s[$i] != $s[$i + 1] && - $s[$i] != $s[$i + 2] && - $s[$i + 1] != $s[$i + 2] - ) { + if ($s[$i] != $s[$i + 1] && $s[$i] != $s[$i + 2] && $s[$i + 1] != $s[$i + 2]) { $cnt++; } } diff --git a/solution/1800-1899/1878.Get Biggest Three Rhombus Sums in a Grid/Solution.go b/solution/1800-1899/1878.Get Biggest Three Rhombus Sums in a Grid/Solution.go index 916f985da74eb..5ee629c759ad3 100644 --- a/solution/1800-1899/1878.Get Biggest Three Rhombus Sums in a Grid/Solution.go +++ b/solution/1800-1899/1878.Get Biggest Three Rhombus Sums in a Grid/Solution.go @@ -1,39 +1,39 @@ -func getBiggestThree(grid [][]int) []int { - m, n := len(grid), len(grid[0]) - s1 := make([][]int, m+1) - s2 := make([][]int, m+1) - for i := range s1 { - s1[i] = make([]int, n+2) - s2[i] = make([]int, n+2) - } - for i := 1; i <= m; i++ { - for j := 1; j <= n; j++ { - s1[i][j] = s1[i-1][j-1] + grid[i-1][j-1] - s2[i][j] = s2[i-1][j+1] + grid[i-1][j-1] - } - } - - ss := treemap.NewWithIntComparator() - for i := 1; i <= m; i++ { - for j := 1; j <= n; j++ { - l := min(i-1, m-i, j-1, n-j) - ss.Put(grid[i-1][j-1], nil) - for k := 1; k <= l; k++ { - a := s1[i+k][j] - s1[i][j-k] - b := s1[i][j+k] - s1[i-k][j] - c := s2[i][j-k] - s2[i-k][j] - d := s2[i+k][j] - s2[i][j+k] - ss.Put(a+b+c+d-grid[i+k-1][j-1]+grid[i-k-1][j-1], nil) - } - for ss.Size() > 3 { - x, _ := ss.Min() - ss.Remove(x.(int)) - } - } - } - ans := make([]int, ss.Size()) - for i, k := range ss.Keys() { - ans[len(ans)-i-1] = k.(int) - } - return ans +func getBiggestThree(grid [][]int) []int { + m, n := len(grid), len(grid[0]) + s1 := make([][]int, m+1) + s2 := make([][]int, m+1) + for i := range s1 { + s1[i] = make([]int, n+2) + s2[i] = make([]int, n+2) + } + for i := 1; i <= m; i++ { + for j := 1; j <= n; j++ { + s1[i][j] = s1[i-1][j-1] + grid[i-1][j-1] + s2[i][j] = s2[i-1][j+1] + grid[i-1][j-1] + } + } + + ss := treemap.NewWithIntComparator() + for i := 1; i <= m; i++ { + for j := 1; j <= n; j++ { + l := min(i-1, m-i, j-1, n-j) + ss.Put(grid[i-1][j-1], nil) + for k := 1; k <= l; k++ { + a := s1[i+k][j] - s1[i][j-k] + b := s1[i][j+k] - s1[i-k][j] + c := s2[i][j-k] - s2[i-k][j] + d := s2[i+k][j] - s2[i][j+k] + ss.Put(a+b+c+d-grid[i+k-1][j-1]+grid[i-k-1][j-1], nil) + } + for ss.Size() > 3 { + x, _ := ss.Min() + ss.Remove(x.(int)) + } + } + } + ans := make([]int, ss.Size()) + for i, k := range ss.Keys() { + ans[len(ans)-i-1] = k.(int) + } + return ans } \ No newline at end of file diff --git a/solution/1800-1899/1879.Minimum XOR Sum of Two Arrays/README.md b/solution/1800-1899/1879.Minimum XOR Sum of Two Arrays/README.md index a8e976f2620f0..1903ef9e1556a 100644 --- a/solution/1800-1899/1879.Minimum XOR Sum of Two Arrays/README.md +++ b/solution/1800-1899/1879.Minimum XOR Sum of Two Arrays/README.md @@ -137,7 +137,8 @@ class Solution { for (int j = 0; j < 1 << n; ++j) { for (int k = 0; k < n; ++k) { if ((j >> k & 1) == 1) { - f[i][j] = Math.min(f[i][j], f[i - 1][j ^ (1 << k)] + (nums1[i - 1] ^ nums2[k])); + f[i][j] + = Math.min(f[i][j], f[i - 1][j ^ (1 << k)] + (nums1[i - 1] ^ nums2[k])); } } } diff --git a/solution/1800-1899/1879.Minimum XOR Sum of Two Arrays/README_EN.md b/solution/1800-1899/1879.Minimum XOR Sum of Two Arrays/README_EN.md index c8b3ba58b4968..1b3bb473c8659 100644 --- a/solution/1800-1899/1879.Minimum XOR Sum of Two Arrays/README_EN.md +++ b/solution/1800-1899/1879.Minimum XOR Sum of Two Arrays/README_EN.md @@ -107,7 +107,8 @@ class Solution { for (int j = 0; j < 1 << n; ++j) { for (int k = 0; k < n; ++k) { if ((j >> k & 1) == 1) { - f[i][j] = Math.min(f[i][j], f[i - 1][j ^ (1 << k)] + (nums1[i - 1] ^ nums2[k])); + f[i][j] + = Math.min(f[i][j], f[i - 1][j ^ (1 << k)] + (nums1[i - 1] ^ nums2[k])); } } } diff --git a/solution/1900-1999/1900.The Earliest and Latest Rounds Where Players Compete/README.md b/solution/1900-1999/1900.The Earliest and Latest Rounds Where Players Compete/README.md index 50143e1ed8128..8da82efa53981 100644 --- a/solution/1900-1999/1900.The Earliest and Latest Rounds Where Players Compete/README.md +++ b/solution/1900-1999/1900.The Earliest and Latest Rounds Where Players Compete/README.md @@ -102,7 +102,6 @@ class Solution: return [a, b] return dp(firstPlayer, n - secondPlayer + 1, n) - ``` ### **Java** diff --git a/solution/1900-1999/1900.The Earliest and Latest Rounds Where Players Compete/README_EN.md b/solution/1900-1999/1900.The Earliest and Latest Rounds Where Players Compete/README_EN.md index 35a38bf73fbfc..f4dc39e4cc1ef 100644 --- a/solution/1900-1999/1900.The Earliest and Latest Rounds Where Players Compete/README_EN.md +++ b/solution/1900-1999/1900.The Earliest and Latest Rounds Where Players Compete/README_EN.md @@ -96,7 +96,6 @@ class Solution: return [a, b] return dp(firstPlayer, n - secondPlayer + 1, n) - ``` ### **Java** diff --git a/solution/1900-1999/1901.Find a Peak Element II/Solution.go b/solution/1900-1999/1901.Find a Peak Element II/Solution.go index b18b1e0951893..ab0bcefd86393 100644 --- a/solution/1900-1999/1901.Find a Peak Element II/Solution.go +++ b/solution/1900-1999/1901.Find a Peak Element II/Solution.go @@ -1,22 +1,22 @@ -func findPeakGrid(mat [][]int) []int { - maxPos := func(arr []int) int { - j := 0 - for i := 1; i < len(arr); i++ { - if arr[i] > arr[j] { - j = i - } - } - return j - } - l, r := 0, len(mat)-1 - for l < r { - mid := (l + r) >> 1 - j := maxPos(mat[mid]) - if mat[mid][j] > mat[mid+1][j] { - r = mid - } else { - l = mid + 1 - } - } - return []int{l, maxPos(mat[l])} +func findPeakGrid(mat [][]int) []int { + maxPos := func(arr []int) int { + j := 0 + for i := 1; i < len(arr); i++ { + if arr[i] > arr[j] { + j = i + } + } + return j + } + l, r := 0, len(mat)-1 + for l < r { + mid := (l + r) >> 1 + j := maxPos(mat[mid]) + if mat[mid][j] > mat[mid+1][j] { + r = mid + } else { + l = mid + 1 + } + } + return []int{l, maxPos(mat[l])} } \ No newline at end of file diff --git a/solution/1900-1999/1931.Painting a Grid With Three Different Colors/Solution.go b/solution/1900-1999/1931.Painting a Grid With Three Different Colors/Solution.go index ea56bde82fbf9..53205f1f34e85 100644 --- a/solution/1900-1999/1931.Painting a Grid With Three Different Colors/Solution.go +++ b/solution/1900-1999/1931.Painting a Grid With Three Different Colors/Solution.go @@ -1,54 +1,54 @@ -func colorTheGrid(m int, n int) (ans int) { - f1 := func(x int) bool { - last := -1 - for i := 0; i < m; i++ { - if x%3 == last { - return false - } - last = x % 3 - x /= 3 - } - return true - } - f2 := func(x, y int) bool { - for i := 0; i < m; i++ { - if x%3 == y%3 { - return false - } - x /= 3 - y /= 3 - } - return true - } - mx := int(math.Pow(3, float64(m))) - valid := map[int]bool{} - f := make([]int, mx) - for i := 0; i < mx; i++ { - if f1(i) { - valid[i] = true - f[i] = 1 - } - } - d := map[int][]int{} - for i := range valid { - for j := range valid { - if f2(i, j) { - d[i] = append(d[i], j) - } - } - } - const mod int = 1e9 + 7 - for k := 1; k < n; k++ { - g := make([]int, mx) - for i := range valid { - for _, j := range d[i] { - g[i] = (g[i] + f[j]) % mod - } - } - f = g - } - for _, x := range f { - ans = (ans + x) % mod - } - return +func colorTheGrid(m int, n int) (ans int) { + f1 := func(x int) bool { + last := -1 + for i := 0; i < m; i++ { + if x%3 == last { + return false + } + last = x % 3 + x /= 3 + } + return true + } + f2 := func(x, y int) bool { + for i := 0; i < m; i++ { + if x%3 == y%3 { + return false + } + x /= 3 + y /= 3 + } + return true + } + mx := int(math.Pow(3, float64(m))) + valid := map[int]bool{} + f := make([]int, mx) + for i := 0; i < mx; i++ { + if f1(i) { + valid[i] = true + f[i] = 1 + } + } + d := map[int][]int{} + for i := range valid { + for j := range valid { + if f2(i, j) { + d[i] = append(d[i], j) + } + } + } + const mod int = 1e9 + 7 + for k := 1; k < n; k++ { + g := make([]int, mx) + for i := range valid { + for _, j := range d[i] { + g[i] = (g[i] + f[j]) % mod + } + } + f = g + } + for _, x := range f { + ans = (ans + x) % mod + } + return } \ No newline at end of file diff --git a/solution/1900-1999/1964.Find the Longest Valid Obstacle Course at Each Position/README.md b/solution/1900-1999/1964.Find the Longest Valid Obstacle Course at Each Position/README.md index 82bd732a35e46..997ba82649317 100644 --- a/solution/1900-1999/1964.Find the Longest Valid Obstacle Course at Each Position/README.md +++ b/solution/1900-1999/1964.Find the Longest Valid Obstacle Course at Each Position/README.md @@ -151,7 +151,6 @@ class BinaryIndexedTree { } } - class Solution { public int[] longestObstacleCourseAtEachPosition(int[] obstacles) { int[] nums = obstacles.clone(); diff --git a/solution/1900-1999/1964.Find the Longest Valid Obstacle Course at Each Position/README_EN.md b/solution/1900-1999/1964.Find the Longest Valid Obstacle Course at Each Position/README_EN.md index b19b2242de75b..6c5b3512f928e 100644 --- a/solution/1900-1999/1964.Find the Longest Valid Obstacle Course at Each Position/README_EN.md +++ b/solution/1900-1999/1964.Find the Longest Valid Obstacle Course at Each Position/README_EN.md @@ -141,7 +141,6 @@ class BinaryIndexedTree { } } - class Solution { public int[] longestObstacleCourseAtEachPosition(int[] obstacles) { int[] nums = obstacles.clone(); diff --git a/solution/2000-2099/2039.The Time When the Network Becomes Idle/README.md b/solution/2000-2099/2039.The Time When the Network Becomes Idle/README.md index 27642095fc26d..6f543c14573c1 100644 --- a/solution/2000-2099/2039.The Time When the Network Becomes Idle/README.md +++ b/solution/2000-2099/2039.The Time When the Network Becomes Idle/README.md @@ -160,7 +160,6 @@ class Solution { return ans; } } - ``` ### **C++** diff --git a/solution/2100-2199/2132.Stamping the Grid/Solution.go b/solution/2100-2199/2132.Stamping the Grid/Solution.go index 0818652690c0d..ef79dd1840cf7 100644 --- a/solution/2100-2199/2132.Stamping the Grid/Solution.go +++ b/solution/2100-2199/2132.Stamping the Grid/Solution.go @@ -36,4 +36,4 @@ func possibleToStamp(grid [][]int, stampHeight int, stampWidth int) bool { } } return true -} +} \ No newline at end of file diff --git a/solution/2200-2299/2204.Distance to a Cycle in Undirected Graph/Solution.go b/solution/2200-2299/2204.Distance to a Cycle in Undirected Graph/Solution.go index 4aba610315b42..3013c39395721 100644 --- a/solution/2200-2299/2204.Distance to a Cycle in Undirected Graph/Solution.go +++ b/solution/2200-2299/2204.Distance to a Cycle in Undirected Graph/Solution.go @@ -1,38 +1,38 @@ -func distanceToCycle(n int, edges [][]int) []int { - g := make([]map[int]bool, n) - for i := range g { - g[i] = map[int]bool{} - } - for _, e := range edges { - a, b := e[0], e[1] - g[a][b] = true - g[b][a] = true - } - q := []int{} - for i := 0; i < n; i++ { - if len(g[i]) == 1 { - q = append(q, i) - } - } - f := make([]int, n) - seq := []int{} - for len(q) > 0 { - i := q[0] - q = q[1:] - seq = append(seq, i) - for j := range g[i] { - delete(g[j], i) - f[i] = j - if len(g[j]) == 1 { - q = append(q, j) - } - } - g[i] = map[int]bool{} - } - ans := make([]int, n) - for k := len(seq) - 1; k >= 0; k-- { - i := seq[k] - ans[i] = ans[f[i]] + 1 - } - return ans +func distanceToCycle(n int, edges [][]int) []int { + g := make([]map[int]bool, n) + for i := range g { + g[i] = map[int]bool{} + } + for _, e := range edges { + a, b := e[0], e[1] + g[a][b] = true + g[b][a] = true + } + q := []int{} + for i := 0; i < n; i++ { + if len(g[i]) == 1 { + q = append(q, i) + } + } + f := make([]int, n) + seq := []int{} + for len(q) > 0 { + i := q[0] + q = q[1:] + seq = append(seq, i) + for j := range g[i] { + delete(g[j], i) + f[i] = j + if len(g[j]) == 1 { + q = append(q, j) + } + } + g[i] = map[int]bool{} + } + ans := make([]int, n) + for k := len(seq) - 1; k >= 0; k-- { + i := seq[k] + ans[i] = ans[f[i]] + 1 + } + return ans } \ No newline at end of file diff --git a/solution/2200-2299/2276.Count Integers in Intervals/Solution.go b/solution/2200-2299/2276.Count Integers in Intervals/Solution.go index 89ba3a3efd548..17715aa9929f9 100644 --- a/solution/2200-2299/2276.Count Integers in Intervals/Solution.go +++ b/solution/2200-2299/2276.Count Integers in Intervals/Solution.go @@ -1,121 +1,121 @@ -type Node struct { - left *Node - right *Node - l int - r int - mid int - v int - add int -} - -type SegmentTree struct { - root *Node -} - -func newNode(l, r int) *Node { - return &Node{ - left: nil, - right: nil, - l: l, - r: r, - mid: (l + r) / 2, - v: 0, - add: 0, - } -} - -func newSegmentTree() *SegmentTree { - return &SegmentTree{ - root: newNode(1, 1000000001), - } -} - -func (st *SegmentTree) modify(l, r, v int, node *Node) { - if node == nil { - node = st.root - } - if l > r { - return - } - if node.l >= l && node.r <= r { - node.v = node.r - node.l + 1 - node.add = v - return - } - st.pushdown(node) - if l <= node.mid { - st.modify(l, r, v, node.left) - } - if r > node.mid { - st.modify(l, r, v, node.right) - } - st.pushup(node) -} - -func (st *SegmentTree) query(l, r int, node *Node) int { - if node == nil { - node = st.root - } - if l > r { - return 0 - } - if node.l >= l && node.r <= r { - return node.v - } - st.pushdown(node) - v := 0 - if l <= node.mid { - v += st.query(l, r, node.left) - } - if r > node.mid { - v += st.query(l, r, node.right) - } - return v -} - -func (st *SegmentTree) pushup(node *Node) { - node.v = node.left.v + node.right.v -} - -func (st *SegmentTree) pushdown(node *Node) { - if node.left == nil { - node.left = newNode(node.l, node.mid) - } - if node.right == nil { - node.right = newNode(node.mid+1, node.r) - } - if node.add != 0 { - left := node.left - right := node.right - left.add = node.add - right.add = node.add - left.v = left.r - left.l + 1 - right.v = right.r - right.l + 1 - node.add = 0 - } -} - -type CountIntervals struct { - tree *SegmentTree -} - -func Constructor() CountIntervals { - return CountIntervals{ - tree: newSegmentTree(), - } -} - -func (ci *CountIntervals) Add(left, right int) { - ci.tree.modify(left, right, 1, nil) -} - -func (ci *CountIntervals) Count() int { - return ci.tree.query(1, 1000000000, nil) -} - -/** - * Your CountIntervals object will be instantiated and called as such: - * obj := Constructor(); - * obj.Add(left,right); - * param_2 := obj.Count(); +type Node struct { + left *Node + right *Node + l int + r int + mid int + v int + add int +} + +type SegmentTree struct { + root *Node +} + +func newNode(l, r int) *Node { + return &Node{ + left: nil, + right: nil, + l: l, + r: r, + mid: (l + r) / 2, + v: 0, + add: 0, + } +} + +func newSegmentTree() *SegmentTree { + return &SegmentTree{ + root: newNode(1, 1000000001), + } +} + +func (st *SegmentTree) modify(l, r, v int, node *Node) { + if node == nil { + node = st.root + } + if l > r { + return + } + if node.l >= l && node.r <= r { + node.v = node.r - node.l + 1 + node.add = v + return + } + st.pushdown(node) + if l <= node.mid { + st.modify(l, r, v, node.left) + } + if r > node.mid { + st.modify(l, r, v, node.right) + } + st.pushup(node) +} + +func (st *SegmentTree) query(l, r int, node *Node) int { + if node == nil { + node = st.root + } + if l > r { + return 0 + } + if node.l >= l && node.r <= r { + return node.v + } + st.pushdown(node) + v := 0 + if l <= node.mid { + v += st.query(l, r, node.left) + } + if r > node.mid { + v += st.query(l, r, node.right) + } + return v +} + +func (st *SegmentTree) pushup(node *Node) { + node.v = node.left.v + node.right.v +} + +func (st *SegmentTree) pushdown(node *Node) { + if node.left == nil { + node.left = newNode(node.l, node.mid) + } + if node.right == nil { + node.right = newNode(node.mid+1, node.r) + } + if node.add != 0 { + left := node.left + right := node.right + left.add = node.add + right.add = node.add + left.v = left.r - left.l + 1 + right.v = right.r - right.l + 1 + node.add = 0 + } +} + +type CountIntervals struct { + tree *SegmentTree +} + +func Constructor() CountIntervals { + return CountIntervals{ + tree: newSegmentTree(), + } +} + +func (ci *CountIntervals) Add(left, right int) { + ci.tree.modify(left, right, 1, nil) +} + +func (ci *CountIntervals) Count() int { + return ci.tree.query(1, 1000000000, nil) +} + +/** + * Your CountIntervals object will be instantiated and called as such: + * obj := Constructor(); + * obj.Add(left,right); + * param_2 := obj.Count(); */ \ No newline at end of file diff --git a/solution/2300-2399/2307.Check for Contradictions in Equations/Solution.go b/solution/2300-2399/2307.Check for Contradictions in Equations/Solution.go index 3c7742bbe6372..142b217549800 100644 --- a/solution/2300-2399/2307.Check for Contradictions in Equations/Solution.go +++ b/solution/2300-2399/2307.Check for Contradictions in Equations/Solution.go @@ -1,47 +1,47 @@ -func checkContradictions(equations [][]string, values []float64) bool { - d := make(map[string]int) - n := 0 - - for _, e := range equations { - for _, s := range e { - if _, ok := d[s]; !ok { - d[s] = n - n++ - } - } - } - - p := make([]int, n) - for i := range p { - p[i] = i - } - - w := make([]float64, n) - for i := range w { - w[i] = 1.0 - } - - var find func(int) int - find = func(x int) int { - if p[x] != x { - root := find(p[x]) - w[x] *= w[p[x]] - p[x] = root - } - return p[x] - } - for i, e := range equations { - a, b := d[e[0]], d[e[1]] - v := values[i] - - pa, pb := find(a), find(b) - if pa != pb { - p[pb] = pa - w[pb] = v * w[a] / w[b] - } else if v*w[a]-w[b] >= 1e-5 || w[b]-v*w[a] >= 1e-5 { - return true - } - } - - return false +func checkContradictions(equations [][]string, values []float64) bool { + d := make(map[string]int) + n := 0 + + for _, e := range equations { + for _, s := range e { + if _, ok := d[s]; !ok { + d[s] = n + n++ + } + } + } + + p := make([]int, n) + for i := range p { + p[i] = i + } + + w := make([]float64, n) + for i := range w { + w[i] = 1.0 + } + + var find func(int) int + find = func(x int) int { + if p[x] != x { + root := find(p[x]) + w[x] *= w[p[x]] + p[x] = root + } + return p[x] + } + for i, e := range equations { + a, b := d[e[0]], d[e[1]] + v := values[i] + + pa, pb := find(a), find(b) + if pa != pb { + p[pb] = pa + w[pb] = v * w[a] / w[b] + } else if v*w[a]-w[b] >= 1e-5 || w[b]-v*w[a] >= 1e-5 { + return true + } + } + + return false } \ No newline at end of file diff --git a/solution/2700-2799/2714.Find Shortest Path with K Hops/README.md b/solution/2700-2799/2714.Find Shortest Path with K Hops/README.md index 94b9f260cc5aa..8e4271844ce9b 100644 --- a/solution/2700-2799/2714.Find Shortest Path with K Hops/README.md +++ b/solution/2700-2799/2714.Find Shortest Path with K Hops/README.md @@ -84,7 +84,9 @@ ```python class Solution: - def shortestPathWithHops(self, n: int, edges: List[List[int]], s: int, d: int, k: int) -> int: + def shortestPathWithHops( + self, n: int, edges: List[List[int]], s: int, d: int, k: int + ) -> int: g = [[] for _ in range(n)] for u, v, w in edges: g[u].append((v, w)) diff --git a/solution/2700-2799/2714.Find Shortest Path with K Hops/README_EN.md b/solution/2700-2799/2714.Find Shortest Path with K Hops/README_EN.md index a5b95d4529274..0e5013776a42c 100644 --- a/solution/2700-2799/2714.Find Shortest Path with K Hops/README_EN.md +++ b/solution/2700-2799/2714.Find Shortest Path with K Hops/README_EN.md @@ -76,7 +76,9 @@ The time complexity is $O(n^2 \times \log n)$, and the space complexity is $O(n ```python class Solution: - def shortestPathWithHops(self, n: int, edges: List[List[int]], s: int, d: int, k: int) -> int: + def shortestPathWithHops( + self, n: int, edges: List[List[int]], s: int, d: int, k: int + ) -> int: g = [[] for _ in range(n)] for u, v, w in edges: g[u].append((v, w)) diff --git a/solution/2700-2799/2736.Maximum Sum Queries/Solution.go b/solution/2700-2799/2736.Maximum Sum Queries/Solution.go index c1af11770f139..8304c6b5fe5db 100644 --- a/solution/2700-2799/2736.Maximum Sum Queries/Solution.go +++ b/solution/2700-2799/2736.Maximum Sum Queries/Solution.go @@ -1,56 +1,56 @@ -type BinaryIndexedTree struct { - n int - c []int -} - -func NewBinaryIndexedTree(n int) BinaryIndexedTree { - c := make([]int, n+1) - for i := range c { - c[i] = -1 - } - return BinaryIndexedTree{n: n, c: c} -} - -func (bit *BinaryIndexedTree) update(x, v int) { - for x <= bit.n { - bit.c[x] = max(bit.c[x], v) - x += x & -x - } -} - -func (bit *BinaryIndexedTree) query(x int) int { - mx := -1 - for x > 0 { - mx = max(mx, bit.c[x]) - x -= x & -x - } - return mx -} - -func maximumSumQueries(nums1 []int, nums2 []int, queries [][]int) []int { - n, m := len(nums1), len(queries) - nums := make([][2]int, n) - for i := range nums { - nums[i] = [2]int{nums1[i], nums2[i]} - } - sort.Slice(nums, func(i, j int) bool { return nums[j][0] < nums[i][0] }) - sort.Ints(nums2) - idx := make([]int, m) - for i := range idx { - idx[i] = i - } - sort.Slice(idx, func(i, j int) bool { return queries[idx[j]][0] < queries[idx[i]][0] }) - tree := NewBinaryIndexedTree(n) - ans := make([]int, m) - j := 0 - for _, i := range idx { - x, y := queries[i][0], queries[i][1] - for ; j < n && nums[j][0] >= x; j++ { - k := n - sort.SearchInts(nums2, nums[j][1]) - tree.update(k, nums[j][0]+nums[j][1]) - } - k := n - sort.SearchInts(nums2, y) - ans[i] = tree.query(k) - } - return ans +type BinaryIndexedTree struct { + n int + c []int +} + +func NewBinaryIndexedTree(n int) BinaryIndexedTree { + c := make([]int, n+1) + for i := range c { + c[i] = -1 + } + return BinaryIndexedTree{n: n, c: c} +} + +func (bit *BinaryIndexedTree) update(x, v int) { + for x <= bit.n { + bit.c[x] = max(bit.c[x], v) + x += x & -x + } +} + +func (bit *BinaryIndexedTree) query(x int) int { + mx := -1 + for x > 0 { + mx = max(mx, bit.c[x]) + x -= x & -x + } + return mx +} + +func maximumSumQueries(nums1 []int, nums2 []int, queries [][]int) []int { + n, m := len(nums1), len(queries) + nums := make([][2]int, n) + for i := range nums { + nums[i] = [2]int{nums1[i], nums2[i]} + } + sort.Slice(nums, func(i, j int) bool { return nums[j][0] < nums[i][0] }) + sort.Ints(nums2) + idx := make([]int, m) + for i := range idx { + idx[i] = i + } + sort.Slice(idx, func(i, j int) bool { return queries[idx[j]][0] < queries[idx[i]][0] }) + tree := NewBinaryIndexedTree(n) + ans := make([]int, m) + j := 0 + for _, i := range idx { + x, y := queries[i][0], queries[i][1] + for ; j < n && nums[j][0] >= x; j++ { + k := n - sort.SearchInts(nums2, nums[j][1]) + tree.update(k, nums[j][0]+nums[j][1]) + } + k := n - sort.SearchInts(nums2, y) + ans[i] = tree.query(k) + } + return ans } \ No newline at end of file diff --git a/solution/2700-2799/2738.Count Occurrences in Text/README_EN.md b/solution/2700-2799/2738.Count Occurrences in Text/README_EN.md index 5ad4aa1fdeb11..67e05710601fb 100644 --- a/solution/2700-2799/2738.Count Occurrences in Text/README_EN.md +++ b/solution/2700-2799/2738.Count Occurrences in Text/README_EN.md @@ -30,7 +30,7 @@ Each row contains file_name and the content of that file. Input:  Files table: +------------+----------------------------------------------------------------------------------+ -| file_name | contenet | +| file_name | content | +------------+----------------------------------------------------------------------------------+ | draft1.txt | The stock exchange predicts a bull market which would make many investors happy. | | draft2.txt | The stock exchange predicts a bull market which would make many investors happy, | diff --git a/solution/2800-2899/2818.Apply Operations to Maximize Score/README.md b/solution/2800-2899/2818.Apply Operations to Maximize Score/README.md index cbf99391536d0..1dc1a1c94f28f 100644 --- a/solution/2800-2899/2818.Apply Operations to Maximize Score/README.md +++ b/solution/2800-2899/2818.Apply Operations to Maximize Score/README.md @@ -94,7 +94,7 @@ def primeFactors(n): class Solution: def maximumScore(self, nums: List[int], k: int) -> int: - mod = 10 ** 9 + 7 + mod = 10**9 + 7 arr = [(i, primeFactors(x), x) for i, x in enumerate(nums)] n = len(nums) diff --git a/solution/2800-2899/2818.Apply Operations to Maximize Score/README_EN.md b/solution/2800-2899/2818.Apply Operations to Maximize Score/README_EN.md index 3d2f016d89573..3485e9a6e9b21 100644 --- a/solution/2800-2899/2818.Apply Operations to Maximize Score/README_EN.md +++ b/solution/2800-2899/2818.Apply Operations to Maximize Score/README_EN.md @@ -86,7 +86,7 @@ def primeFactors(n): class Solution: def maximumScore(self, nums: List[int], k: int) -> int: - mod = 10 ** 9 + 7 + mod = 10**9 + 7 arr = [(i, primeFactors(x), x) for i, x in enumerate(nums)] n = len(nums) diff --git a/solution/2800-2899/2873.Maximum Value of an Ordered Triplet I/README.md b/solution/2800-2899/2873.Maximum Value of an Ordered Triplet I/README.md index 73dd7ba78943b..23990937b36f3 100644 --- a/solution/2800-2899/2873.Maximum Value of an Ordered Triplet I/README.md +++ b/solution/2800-2899/2873.Maximum Value of an Ordered Triplet I/README.md @@ -95,7 +95,6 @@ class Solution { return ans; } } - ``` ### **C++** diff --git a/solution/2800-2899/2873.Maximum Value of an Ordered Triplet I/README_EN.md b/solution/2800-2899/2873.Maximum Value of an Ordered Triplet I/README_EN.md index 8420bb17d5e0e..b60e2ab66ddf4 100644 --- a/solution/2800-2899/2873.Maximum Value of an Ordered Triplet I/README_EN.md +++ b/solution/2800-2899/2873.Maximum Value of an Ordered Triplet I/README_EN.md @@ -85,7 +85,6 @@ class Solution { return ans; } } - ``` ### **C++** diff --git a/solution/2800-2899/2874.Maximum Value of an Ordered Triplet II/README.md b/solution/2800-2899/2874.Maximum Value of an Ordered Triplet II/README.md index 753e63ddfd6d9..08df7255e5af8 100644 --- a/solution/2800-2899/2874.Maximum Value of an Ordered Triplet II/README.md +++ b/solution/2800-2899/2874.Maximum Value of an Ordered Triplet II/README.md @@ -95,7 +95,6 @@ class Solution { return ans; } } - ``` ### **C++** diff --git a/solution/2800-2899/2874.Maximum Value of an Ordered Triplet II/README_EN.md b/solution/2800-2899/2874.Maximum Value of an Ordered Triplet II/README_EN.md index 069657fd7d44d..3dea2a4c238fa 100644 --- a/solution/2800-2899/2874.Maximum Value of an Ordered Triplet II/README_EN.md +++ b/solution/2800-2899/2874.Maximum Value of an Ordered Triplet II/README_EN.md @@ -85,7 +85,6 @@ class Solution { return ans; } } - ``` ### **C++** diff --git a/solution/2800-2899/2875.Minimum Size Subarray in Infinite Array/README.md b/solution/2800-2899/2875.Minimum Size Subarray in Infinite Array/README.md index 00f36fe426692..18fa4ec3a08c4 100644 --- a/solution/2800-2899/2875.Minimum Size Subarray in Infinite Array/README.md +++ b/solution/2800-2899/2875.Minimum Size Subarray in Infinite Array/README.md @@ -180,7 +180,6 @@ class Solution { return res == -1 ? -1 : ans + res; } } - ``` ### **C++** diff --git a/solution/2800-2899/2875.Minimum Size Subarray in Infinite Array/README_EN.md b/solution/2800-2899/2875.Minimum Size Subarray in Infinite Array/README_EN.md index 6f2a964a65251..681029d981293 100644 --- a/solution/2800-2899/2875.Minimum Size Subarray in Infinite Array/README_EN.md +++ b/solution/2800-2899/2875.Minimum Size Subarray in Infinite Array/README_EN.md @@ -171,7 +171,6 @@ class Solution { return res == -1 ? -1 : ans + res; } } - ``` ### **C++** diff --git a/solution/2800-2899/2885.Rename Columns/README.md b/solution/2800-2899/2885.Rename Columns/README.md index 5ae557f2c18b7..85bbab8ebc832 100644 --- a/solution/2800-2899/2885.Rename Columns/README.md +++ b/solution/2800-2899/2885.Rename Columns/README.md @@ -72,8 +72,15 @@ import pandas as pd def renameColumns(students: pd.DataFrame) -> pd.DataFrame: - students.rename(columns={'id': 'student_id', 'first': 'first_name', 'last': 'last_name', 'age': 'age_in_years'}, - inplace=True) + students.rename( + columns={ + 'id': 'student_id', + 'first': 'first_name', + 'last': 'last_name', + 'age': 'age_in_years', + }, + inplace=True, + ) return students ``` diff --git a/solution/2800-2899/2885.Rename Columns/README_EN.md b/solution/2800-2899/2885.Rename Columns/README_EN.md index 5cfcf0e649a6b..8a3301e3b1723 100644 --- a/solution/2800-2899/2885.Rename Columns/README_EN.md +++ b/solution/2800-2899/2885.Rename Columns/README_EN.md @@ -64,8 +64,15 @@ import pandas as pd def renameColumns(students: pd.DataFrame) -> pd.DataFrame: - students.rename(columns={'id': 'student_id', 'first': 'first_name', 'last': 'last_name', 'age': 'age_in_years'}, - inplace=True) + students.rename( + columns={ + 'id': 'student_id', + 'first': 'first_name', + 'last': 'last_name', + 'age': 'age_in_years', + }, + inplace=True, + ) return students ``` diff --git a/solution/2800-2899/2891.Method Chaining/README.md b/solution/2800-2899/2891.Method Chaining/README.md index 4da0cb5c9db3a..dfb6d9486e356 100644 --- a/solution/2800-2899/2891.Method Chaining/README.md +++ b/solution/2800-2899/2891.Method Chaining/README.md @@ -76,7 +76,9 @@ import pandas as pd def findHeavyAnimals(animals: pd.DataFrame) -> pd.DataFrame: - return animals[animals['weight'] > 100].sort_values('weight', ascending=False)[['name']] + return animals[animals['weight'] > 100].sort_values('weight', ascending=False)[ + ['name'] + ] ``` ### **...** diff --git a/solution/2800-2899/2891.Method Chaining/README_EN.md b/solution/2800-2899/2891.Method Chaining/README_EN.md index 79f394a33c328..622eef06e0a48 100644 --- a/solution/2800-2899/2891.Method Chaining/README_EN.md +++ b/solution/2800-2899/2891.Method Chaining/README_EN.md @@ -68,7 +68,9 @@ import pandas as pd def findHeavyAnimals(animals: pd.DataFrame) -> pd.DataFrame: - return animals[animals['weight'] > 100].sort_values('weight', ascending=False)[['name']] + return animals[animals['weight'] > 100].sort_values('weight', ascending=False)[ + ['name'] + ] ``` ### **...** diff --git a/solution/2900-2999/2902.Count of Sub-Multisets With Bounded Sum/README.md b/solution/2900-2999/2902.Count of Sub-Multisets With Bounded Sum/README.md index 7418fc914e96a..eea504b5136cd 100644 --- a/solution/2900-2999/2902.Count of Sub-Multisets With Bounded Sum/README.md +++ b/solution/2900-2999/2902.Count of Sub-Multisets With Bounded Sum/README.md @@ -89,7 +89,6 @@ class Solution: dp[i] = stride[i] return (zeros + 1) * sum(dp[l : r + 1]) % kMod - ``` ### **Java** @@ -121,7 +120,8 @@ class Solution { int c = e.getValue(); sum = Math.min(sum + c * num, r); // prefix part - // dp[i] = dp[i] + dp[i - num] + ... + dp[i - c*num] + dp[i-(c+1)*num] + ... + dp[i % num] + // dp[i] = dp[i] + dp[i - num] + ... + dp[i - c*num] + dp[i-(c+1)*num] + ... + dp[i % + // num] for (int i = num; i <= sum; i++) { dp[i] = (dp[i] + dp[i - num]) % MOD; } @@ -141,7 +141,6 @@ class Solution { return ans; } } - ``` ### **C++** diff --git a/solution/2900-2999/2902.Count of Sub-Multisets With Bounded Sum/README_EN.md b/solution/2900-2999/2902.Count of Sub-Multisets With Bounded Sum/README_EN.md index 98bdda2d3db57..fcc04e36d271a 100644 --- a/solution/2900-2999/2902.Count of Sub-Multisets With Bounded Sum/README_EN.md +++ b/solution/2900-2999/2902.Count of Sub-Multisets With Bounded Sum/README_EN.md @@ -81,7 +81,6 @@ class Solution: dp[i] = stride[i] return (zeros + 1) * sum(dp[l : r + 1]) % kMod - ``` ### **Java** @@ -111,7 +110,8 @@ class Solution { int c = e.getValue(); sum = Math.min(sum + c * num, r); // prefix part - // dp[i] = dp[i] + dp[i - num] + ... + dp[i - c*num] + dp[i-(c+1)*num] + ... + dp[i % num] + // dp[i] = dp[i] + dp[i - num] + ... + dp[i - c*num] + dp[i-(c+1)*num] + ... + dp[i % + // num] for (int i = num; i <= sum; i++) { dp[i] = (dp[i] + dp[i - num]) % MOD; } @@ -131,7 +131,6 @@ class Solution { return ans; } } - ``` ### **C++** diff --git a/solution/2900-2999/2904.Shortest and Lexicographically Smallest Beautiful String/README.md b/solution/2900-2999/2904.Shortest and Lexicographically Smallest Beautiful String/README.md index eb4ad74d2a0d0..b57e63a852b89 100644 --- a/solution/2900-2999/2904.Shortest and Lexicographically Smallest Beautiful String/README.md +++ b/solution/2900-2999/2904.Shortest and Lexicographically Smallest Beautiful String/README.md @@ -145,7 +145,9 @@ class Solution { for (char c : t.toCharArray()) { cnt += c - '0'; } - if (cnt == k && ("".equals(ans) || j - i < ans.length() || (j - i == ans.length() && t.compareTo(ans) < 0))) { + if (cnt == k + && ("".equals(ans) || j - i < ans.length() + || (j - i == ans.length() && t.compareTo(ans) < 0))) { ans = t; } } diff --git a/solution/2900-2999/2904.Shortest and Lexicographically Smallest Beautiful String/README_EN.md b/solution/2900-2999/2904.Shortest and Lexicographically Smallest Beautiful String/README_EN.md index 79d625c320b43..59d93e2ce2020 100644 --- a/solution/2900-2999/2904.Shortest and Lexicographically Smallest Beautiful String/README_EN.md +++ b/solution/2900-2999/2904.Shortest and Lexicographically Smallest Beautiful String/README_EN.md @@ -135,7 +135,9 @@ class Solution { for (char c : t.toCharArray()) { cnt += c - '0'; } - if (cnt == k && ("".equals(ans) || j - i < ans.length() || (j - i == ans.length() && t.compareTo(ans) < 0))) { + if (cnt == k + && ("".equals(ans) || j - i < ans.length() + || (j - i == ans.length() && t.compareTo(ans) < 0))) { ans = t; } } diff --git a/solution/2900-2999/2912.Number of Ways to Reach Destination in the Grid/README.md b/solution/2900-2999/2912.Number of Ways to Reach Destination in the Grid/README.md index f3a85aa95c1d7..3edd6d679a683 100644 --- a/solution/2900-2999/2912.Number of Ways to Reach Destination in the Grid/README.md +++ b/solution/2900-2999/2912.Number of Ways to Reach Destination in the Grid/README.md @@ -98,7 +98,9 @@ $$ ```python class Solution: - def numberOfWays(self, n: int, m: int, k: int, source: List[int], dest: List[int]) -> int: + def numberOfWays( + self, n: int, m: int, k: int, source: List[int], dest: List[int] + ) -> int: mod = 10**9 + 7 a, b, c, d = 1, 0, 0, 0 for _ in range(k): @@ -114,7 +116,9 @@ class Solution: ```python class Solution: - def numberOfWays(self, n: int, m: int, k: int, source: List[int], dest: List[int]) -> int: + def numberOfWays( + self, n: int, m: int, k: int, source: List[int], dest: List[int] + ) -> int: mod = 10**9 + 7 f = [1, 0, 0, 0] for _ in range(k): diff --git a/solution/2900-2999/2912.Number of Ways to Reach Destination in the Grid/README_EN.md b/solution/2900-2999/2912.Number of Ways to Reach Destination in the Grid/README_EN.md index dcb4583c17490..9f62f15eeeca9 100644 --- a/solution/2900-2999/2912.Number of Ways to Reach Destination in the Grid/README_EN.md +++ b/solution/2900-2999/2912.Number of Ways to Reach Destination in the Grid/README_EN.md @@ -90,7 +90,9 @@ The time complexity is $O(k)$, where $k$ is the number of moves. The space compl ```python class Solution: - def numberOfWays(self, n: int, m: int, k: int, source: List[int], dest: List[int]) -> int: + def numberOfWays( + self, n: int, m: int, k: int, source: List[int], dest: List[int] + ) -> int: mod = 10**9 + 7 a, b, c, d = 1, 0, 0, 0 for _ in range(k): @@ -106,7 +108,9 @@ class Solution: ```python class Solution: - def numberOfWays(self, n: int, m: int, k: int, source: List[int], dest: List[int]) -> int: + def numberOfWays( + self, n: int, m: int, k: int, source: List[int], dest: List[int] + ) -> int: mod = 10**9 + 7 f = [1, 0, 0, 0] for _ in range(k): diff --git a/solution/2900-2999/2925.Maximum Score After Applying Operations on a Tree/Solution.go b/solution/2900-2999/2925.Maximum Score After Applying Operations on a Tree/Solution.go index 620386deb4f07..714b63e527c17 100644 --- a/solution/2900-2999/2925.Maximum Score After Applying Operations on a Tree/Solution.go +++ b/solution/2900-2999/2925.Maximum Score After Applying Operations on a Tree/Solution.go @@ -1,27 +1,27 @@ -func maximumScoreAfterOperations(edges [][]int, values []int) int64 { - g := make([][]int, len(values)) - for _, e := range edges { - a, b := e[0], e[1] - g[a] = append(g[a], b) - g[b] = append(g[b], a) - } - var dfs func(int, int) (int64, int64) - dfs = func(i, fa int) (int64, int64) { - a, b := int64(0), int64(0) - leaf := true - for _, j := range g[i] { - if j != fa { - leaf = false - aa, bb := dfs(j, i) - a += aa - b += bb - } - } - if leaf { - return int64(values[i]), int64(0) - } - return int64(values[i]) + a, max(int64(values[i])+b, a) - } - _, b := dfs(0, -1) - return b +func maximumScoreAfterOperations(edges [][]int, values []int) int64 { + g := make([][]int, len(values)) + for _, e := range edges { + a, b := e[0], e[1] + g[a] = append(g[a], b) + g[b] = append(g[b], a) + } + var dfs func(int, int) (int64, int64) + dfs = func(i, fa int) (int64, int64) { + a, b := int64(0), int64(0) + leaf := true + for _, j := range g[i] { + if j != fa { + leaf = false + aa, bb := dfs(j, i) + a += aa + b += bb + } + } + if leaf { + return int64(values[i]), int64(0) + } + return int64(values[i]) + a, max(int64(values[i])+b, a) + } + _, b := dfs(0, -1) + return b } \ No newline at end of file diff --git a/solution/2900-2999/2926.Maximum Balanced Subsequence Sum/Solution.go b/solution/2900-2999/2926.Maximum Balanced Subsequence Sum/Solution.go index 845cdd7871731..28756c6e83de8 100644 --- a/solution/2900-2999/2926.Maximum Balanced Subsequence Sum/Solution.go +++ b/solution/2900-2999/2926.Maximum Balanced Subsequence Sum/Solution.go @@ -1,54 +1,54 @@ -const inf int = 1e18 - -type BinaryIndexedTree struct { - n int - c []int -} - -func NewBinaryIndexedTree(n int) BinaryIndexedTree { - c := make([]int, n+1) - for i := range c { - c[i] = -inf - } - return BinaryIndexedTree{n: n, c: c} -} - -func (bit *BinaryIndexedTree) update(x, v int) { - for x <= bit.n { - bit.c[x] = max(bit.c[x], v) - x += x & -x - } -} - -func (bit *BinaryIndexedTree) query(x int) int { - mx := -inf - for x > 0 { - mx = max(mx, bit.c[x]) - x -= x & -x - } - return mx -} - -func maxBalancedSubsequenceSum(nums []int) int64 { - n := len(nums) - arr := make([]int, n) - for i, x := range nums { - arr[i] = x - i - } - sort.Ints(arr) - m := 0 - for i, x := range arr { - if i == 0 || x != arr[i-1] { - arr[m] = x - m++ - } - } - arr = arr[:m] - tree := NewBinaryIndexedTree(m) - for i, x := range nums { - j := sort.SearchInts(arr, x-i) + 1 - v := max(tree.query(j), 0) + x - tree.update(j, v) - } - return int64(tree.query(m)) +const inf int = 1e18 + +type BinaryIndexedTree struct { + n int + c []int +} + +func NewBinaryIndexedTree(n int) BinaryIndexedTree { + c := make([]int, n+1) + for i := range c { + c[i] = -inf + } + return BinaryIndexedTree{n: n, c: c} +} + +func (bit *BinaryIndexedTree) update(x, v int) { + for x <= bit.n { + bit.c[x] = max(bit.c[x], v) + x += x & -x + } +} + +func (bit *BinaryIndexedTree) query(x int) int { + mx := -inf + for x > 0 { + mx = max(mx, bit.c[x]) + x -= x & -x + } + return mx +} + +func maxBalancedSubsequenceSum(nums []int) int64 { + n := len(nums) + arr := make([]int, n) + for i, x := range nums { + arr[i] = x - i + } + sort.Ints(arr) + m := 0 + for i, x := range arr { + if i == 0 || x != arr[i-1] { + arr[m] = x + m++ + } + } + arr = arr[:m] + tree := NewBinaryIndexedTree(m) + for i, x := range nums { + j := sort.SearchInts(arr, x-i) + 1 + v := max(tree.query(j), 0) + x + tree.update(j, v) + } + return int64(tree.query(m)) } \ No newline at end of file diff --git a/solution/2900-2999/2927.Distribute Candies Among Children III/README.md b/solution/2900-2999/2927.Distribute Candies Among Children III/README.md index 6759b894cad96..dbfa88743504a 100644 --- a/solution/2900-2999/2927.Distribute Candies Among Children III/README.md +++ b/solution/2900-2999/2927.Distribute Candies Among Children III/README.md @@ -130,7 +130,7 @@ func distributeCandies(n int, limit int) int64 { if n > 3*limit { return 0 } - ans := comb2(n+2) + ans := comb2(n + 2) if n > limit { ans -= 3 * comb2(n-limit+1) } diff --git a/solution/2900-2999/2927.Distribute Candies Among Children III/README_EN.md b/solution/2900-2999/2927.Distribute Candies Among Children III/README_EN.md index aa0b6dd2054ee..c79f90240ad38 100644 --- a/solution/2900-2999/2927.Distribute Candies Among Children III/README_EN.md +++ b/solution/2900-2999/2927.Distribute Candies Among Children III/README_EN.md @@ -120,7 +120,7 @@ func distributeCandies(n int, limit int) int64 { if n > 3*limit { return 0 } - ans := comb2(n+2) + ans := comb2(n + 2) if n > limit { ans -= 3 * comb2(n-limit+1) } diff --git a/solution/2900-2999/2927.Distribute Candies Among Children III/Solution.go b/solution/2900-2999/2927.Distribute Candies Among Children III/Solution.go index 7705fb2057848..1a7f2ed237e81 100644 --- a/solution/2900-2999/2927.Distribute Candies Among Children III/Solution.go +++ b/solution/2900-2999/2927.Distribute Candies Among Children III/Solution.go @@ -5,7 +5,7 @@ func distributeCandies(n int, limit int) int64 { if n > 3*limit { return 0 } - ans := comb2(n+2) + ans := comb2(n + 2) if n > limit { ans -= 3 * comb2(n-limit+1) } diff --git a/solution/2900-2999/2929.Distribute Candies Among Children II/README.md b/solution/2900-2999/2929.Distribute Candies Among Children II/README.md index 3423f948ca031..4c63cbdf02fd5 100644 --- a/solution/2900-2999/2929.Distribute Candies Among Children II/README.md +++ b/solution/2900-2999/2929.Distribute Candies Among Children II/README.md @@ -130,7 +130,7 @@ func distributeCandies(n int, limit int) int64 { if n > 3*limit { return 0 } - ans := comb2(n+2) + ans := comb2(n + 2) if n > limit { ans -= 3 * comb2(n-limit+1) } diff --git a/solution/2900-2999/2929.Distribute Candies Among Children II/README_EN.md b/solution/2900-2999/2929.Distribute Candies Among Children II/README_EN.md index 2aea8b3a40a1a..3afb9147b88ee 100644 --- a/solution/2900-2999/2929.Distribute Candies Among Children II/README_EN.md +++ b/solution/2900-2999/2929.Distribute Candies Among Children II/README_EN.md @@ -120,7 +120,7 @@ func distributeCandies(n int, limit int) int64 { if n > 3*limit { return 0 } - ans := comb2(n+2) + ans := comb2(n + 2) if n > limit { ans -= 3 * comb2(n-limit+1) } diff --git a/solution/2900-2999/2929.Distribute Candies Among Children II/Solution.go b/solution/2900-2999/2929.Distribute Candies Among Children II/Solution.go index 7705fb2057848..1a7f2ed237e81 100644 --- a/solution/2900-2999/2929.Distribute Candies Among Children II/Solution.go +++ b/solution/2900-2999/2929.Distribute Candies Among Children II/Solution.go @@ -5,7 +5,7 @@ func distributeCandies(n int, limit int) int64 { if n > 3*limit { return 0 } - ans := comb2(n+2) + ans := comb2(n + 2) if n > limit { ans -= 3 * comb2(n-limit+1) } diff --git a/solution/2900-2999/2930.Number of Strings Which Can Be Rearranged to Contain Substring/Solution.go b/solution/2900-2999/2930.Number of Strings Which Can Be Rearranged to Contain Substring/Solution.go index ded6388eea146..efc876fbcea4d 100644 --- a/solution/2900-2999/2930.Number of Strings Which Can Be Rearranged to Contain Substring/Solution.go +++ b/solution/2900-2999/2930.Number of Strings Which Can Be Rearranged to Contain Substring/Solution.go @@ -1,22 +1,22 @@ -func stringCount(n int) int { - const mod int = 1e9 + 7 - qpow := func(a, n int) int { - ans := 1 - for ; n > 0; n >>= 1 { - if n&1 == 1 { - ans = ans * a % mod - } - a = a * a % mod - } - return ans - } - a := qpow(25, n) - b := a - c := qpow(25, n) + n*qpow(25, n-1) - ab := qpow(24, n) - ac := (qpow(24, n) + n*qpow(24, n-1)) % mod - bc := ac - abc := (qpow(23, n) + n*qpow(23, n-1)) % mod - tot := qpow(26, n) - return ((tot-(a+b+c-ab-ac-bc+abc))%mod + mod) % mod +func stringCount(n int) int { + const mod int = 1e9 + 7 + qpow := func(a, n int) int { + ans := 1 + for ; n > 0; n >>= 1 { + if n&1 == 1 { + ans = ans * a % mod + } + a = a * a % mod + } + return ans + } + a := qpow(25, n) + b := a + c := qpow(25, n) + n*qpow(25, n-1) + ab := qpow(24, n) + ac := (qpow(24, n) + n*qpow(24, n-1)) % mod + bc := ac + abc := (qpow(23, n) + n*qpow(23, n-1)) % mod + tot := qpow(26, n) + return ((tot-(a+b+c-ab-ac-bc+abc))%mod + mod) % mod } \ No newline at end of file diff --git a/solution/2900-2999/2931.Maximum Spending After Buying Items/Solution.go b/solution/2900-2999/2931.Maximum Spending After Buying Items/Solution.go index 44fa6284522a1..b22c843380f4f 100644 --- a/solution/2900-2999/2931.Maximum Spending After Buying Items/Solution.go +++ b/solution/2900-2999/2931.Maximum Spending After Buying Items/Solution.go @@ -1,24 +1,24 @@ -func maxSpending(values [][]int) (ans int64) { - pq := hp{} - n := len(values[0]) - for i, row := range values { - heap.Push(&pq, tuple{row[n-1], i, n - 1}) - } - for d := 1; len(pq) > 0; d++ { - p := heap.Pop(&pq).(tuple) - ans += int64(p.v * d) - if p.j > 0 { - heap.Push(&pq, tuple{values[p.i][p.j-1], p.i, p.j - 1}) - } - } - return -} - -type tuple struct{ v, i, j int } -type hp []tuple - -func (h hp) Len() int { return len(h) } -func (h hp) Less(i, j int) bool { return h[i].v < h[j].v } -func (h hp) Swap(i, j int) { h[i], h[j] = h[j], h[i] } -func (h *hp) Push(v any) { *h = append(*h, v.(tuple)) } +func maxSpending(values [][]int) (ans int64) { + pq := hp{} + n := len(values[0]) + for i, row := range values { + heap.Push(&pq, tuple{row[n-1], i, n - 1}) + } + for d := 1; len(pq) > 0; d++ { + p := heap.Pop(&pq).(tuple) + ans += int64(p.v * d) + if p.j > 0 { + heap.Push(&pq, tuple{values[p.i][p.j-1], p.i, p.j - 1}) + } + } + return +} + +type tuple struct{ v, i, j int } +type hp []tuple + +func (h hp) Len() int { return len(h) } +func (h hp) Less(i, j int) bool { return h[i].v < h[j].v } +func (h hp) Swap(i, j int) { h[i], h[j] = h[j], h[i] } +func (h *hp) Push(v any) { *h = append(*h, v.(tuple)) } func (h *hp) Pop() any { a := *h; v := a[len(a)-1]; *h = a[:len(a)-1]; return v } \ No newline at end of file diff --git a/solution/2900-2999/2932.Maximum Strong Pair XOR I/README.md b/solution/2900-2999/2932.Maximum Strong Pair XOR I/README.md index 53a6a130342f4..2637f8ad2a6d4 100644 --- a/solution/2900-2999/2932.Maximum Strong Pair XOR I/README.md +++ b/solution/2900-2999/2932.Maximum Strong Pair XOR I/README.md @@ -163,7 +163,6 @@ class Trie { private int cnt = 0; public Trie() { - } public void insert(int x) { diff --git a/solution/2900-2999/2932.Maximum Strong Pair XOR I/README_EN.md b/solution/2900-2999/2932.Maximum Strong Pair XOR I/README_EN.md index 5ec8064b78ef9..bfc9390898594 100644 --- a/solution/2900-2999/2932.Maximum Strong Pair XOR I/README_EN.md +++ b/solution/2900-2999/2932.Maximum Strong Pair XOR I/README_EN.md @@ -153,7 +153,6 @@ class Trie { private int cnt = 0; public Trie() { - } public void insert(int x) { diff --git a/solution/2900-2999/2932.Maximum Strong Pair XOR I/Solution.go b/solution/2900-2999/2932.Maximum Strong Pair XOR I/Solution.go index 88836f9e00dc1..77fcaa2665535 100644 --- a/solution/2900-2999/2932.Maximum Strong Pair XOR I/Solution.go +++ b/solution/2900-2999/2932.Maximum Strong Pair XOR I/Solution.go @@ -1,58 +1,58 @@ -type Trie struct { - children [2]*Trie - cnt int -} - -func newTrie() *Trie { - return &Trie{} -} - -func (t *Trie) insert(x int) { - node := t - for i := 7; i >= 0; i-- { - v := (x >> uint(i)) & 1 - if node.children[v] == nil { - node.children[v] = newTrie() - } - node = node.children[v] - node.cnt++ - } -} - -func (t *Trie) search(x int) int { - node := t - ans := 0 - for i := 7; i >= 0; i-- { - v := (x >> uint(i)) & 1 - if node.children[v^1] != nil && node.children[v^1].cnt > 0 { - ans |= 1 << uint(i) - node = node.children[v^1] - } else { - node = node.children[v] - } - } - return ans -} - -func (t *Trie) remove(x int) { - node := t - for i := 7; i >= 0; i-- { - v := (x >> uint(i)) & 1 - node = node.children[v] - node.cnt-- - } -} - -func maximumStrongPairXor(nums []int) (ans int) { - sort.Ints(nums) - tree := newTrie() - i := 0 - for _, y := range nums { - tree.insert(y) - for ; y > nums[i]*2; i++ { - tree.remove(nums[i]) - } - ans = max(ans, tree.search(y)) - } - return ans +type Trie struct { + children [2]*Trie + cnt int +} + +func newTrie() *Trie { + return &Trie{} +} + +func (t *Trie) insert(x int) { + node := t + for i := 7; i >= 0; i-- { + v := (x >> uint(i)) & 1 + if node.children[v] == nil { + node.children[v] = newTrie() + } + node = node.children[v] + node.cnt++ + } +} + +func (t *Trie) search(x int) int { + node := t + ans := 0 + for i := 7; i >= 0; i-- { + v := (x >> uint(i)) & 1 + if node.children[v^1] != nil && node.children[v^1].cnt > 0 { + ans |= 1 << uint(i) + node = node.children[v^1] + } else { + node = node.children[v] + } + } + return ans +} + +func (t *Trie) remove(x int) { + node := t + for i := 7; i >= 0; i-- { + v := (x >> uint(i)) & 1 + node = node.children[v] + node.cnt-- + } +} + +func maximumStrongPairXor(nums []int) (ans int) { + sort.Ints(nums) + tree := newTrie() + i := 0 + for _, y := range nums { + tree.insert(y) + for ; y > nums[i]*2; i++ { + tree.remove(nums[i]) + } + ans = max(ans, tree.search(y)) + } + return ans } \ No newline at end of file diff --git a/solution/2900-2999/2933.High-Access Employees/Solution.go b/solution/2900-2999/2933.High-Access Employees/Solution.go index 5f382a39bb050..29fdda2a4b9a1 100644 --- a/solution/2900-2999/2933.High-Access Employees/Solution.go +++ b/solution/2900-2999/2933.High-Access Employees/Solution.go @@ -1,20 +1,20 @@ -func findHighAccessEmployees(access_times [][]string) (ans []string) { - d := map[string][]int{} - for _, e := range access_times { - name, s := e[0], e[1] - h, _ := strconv.Atoi(s[:2]) - m, _ := strconv.Atoi(s[2:]) - t := h*60 + m - d[name] = append(d[name], t) - } - for name, ts := range d { - sort.Ints(ts) - for i := 2; i < len(ts); i++ { - if ts[i]-ts[i-2] < 60 { - ans = append(ans, name) - break - } - } - } - return +func findHighAccessEmployees(access_times [][]string) (ans []string) { + d := map[string][]int{} + for _, e := range access_times { + name, s := e[0], e[1] + h, _ := strconv.Atoi(s[:2]) + m, _ := strconv.Atoi(s[2:]) + t := h*60 + m + d[name] = append(d[name], t) + } + for name, ts := range d { + sort.Ints(ts) + for i := 2; i < len(ts); i++ { + if ts[i]-ts[i-2] < 60 { + ans = append(ans, name) + break + } + } + } + return } \ No newline at end of file diff --git a/solution/2900-2999/2934.Minimum Operations to Maximize Last Elements in Arrays/Solution.go b/solution/2900-2999/2934.Minimum Operations to Maximize Last Elements in Arrays/Solution.go index a265adeacccce..8603225a4dd5b 100644 --- a/solution/2900-2999/2934.Minimum Operations to Maximize Last Elements in Arrays/Solution.go +++ b/solution/2900-2999/2934.Minimum Operations to Maximize Last Elements in Arrays/Solution.go @@ -1,21 +1,21 @@ -func minOperations(nums1 []int, nums2 []int) int { - n := len(nums1) - f := func(x, y int) (cnt int) { - for i, a := range nums1[:n-1] { - b := nums2[i] - if a <= x && b <= y { - continue - } - if !(a <= y && b <= x) { - return -1 - } - cnt++ - } - return - } - a, b := f(nums1[n-1], nums2[n-1]), f(nums2[n-1], nums1[n-1]) - if a+b == -2 { - return -1 - } - return min(a, b+1) +func minOperations(nums1 []int, nums2 []int) int { + n := len(nums1) + f := func(x, y int) (cnt int) { + for i, a := range nums1[:n-1] { + b := nums2[i] + if a <= x && b <= y { + continue + } + if !(a <= y && b <= x) { + return -1 + } + cnt++ + } + return + } + a, b := f(nums1[n-1], nums2[n-1]), f(nums2[n-1], nums1[n-1]) + if a+b == -2 { + return -1 + } + return min(a, b+1) } \ No newline at end of file diff --git a/solution/2900-2999/2935.Maximum Strong Pair XOR II/README.md b/solution/2900-2999/2935.Maximum Strong Pair XOR II/README.md index 0f723d6b17db9..0e1ef0f490175 100644 --- a/solution/2900-2999/2935.Maximum Strong Pair XOR II/README.md +++ b/solution/2900-2999/2935.Maximum Strong Pair XOR II/README.md @@ -135,7 +135,6 @@ class Trie { private int cnt = 0; public Trie() { - } public void insert(int x) { diff --git a/solution/2900-2999/2935.Maximum Strong Pair XOR II/README_EN.md b/solution/2900-2999/2935.Maximum Strong Pair XOR II/README_EN.md index 13f7298a1b7dd..ee2c4c1e54fcb 100644 --- a/solution/2900-2999/2935.Maximum Strong Pair XOR II/README_EN.md +++ b/solution/2900-2999/2935.Maximum Strong Pair XOR II/README_EN.md @@ -125,7 +125,6 @@ class Trie { private int cnt = 0; public Trie() { - } public void insert(int x) { diff --git a/solution/2900-2999/2935.Maximum Strong Pair XOR II/Solution.go b/solution/2900-2999/2935.Maximum Strong Pair XOR II/Solution.go index 6d6b3a07c3290..f47fb670f11a3 100644 --- a/solution/2900-2999/2935.Maximum Strong Pair XOR II/Solution.go +++ b/solution/2900-2999/2935.Maximum Strong Pair XOR II/Solution.go @@ -1,58 +1,58 @@ -type Trie struct { - children [2]*Trie - cnt int -} - -func newTrie() *Trie { - return &Trie{} -} - -func (t *Trie) insert(x int) { - node := t - for i := 20; i >= 0; i-- { - v := (x >> uint(i)) & 1 - if node.children[v] == nil { - node.children[v] = newTrie() - } - node = node.children[v] - node.cnt++ - } -} - -func (t *Trie) search(x int) int { - node := t - ans := 0 - for i := 20; i >= 0; i-- { - v := (x >> uint(i)) & 1 - if node.children[v^1] != nil && node.children[v^1].cnt > 0 { - ans |= 1 << uint(i) - node = node.children[v^1] - } else { - node = node.children[v] - } - } - return ans -} - -func (t *Trie) remove(x int) { - node := t - for i := 20; i >= 0; i-- { - v := (x >> uint(i)) & 1 - node = node.children[v] - node.cnt-- - } -} - -func maximumStrongPairXor(nums []int) (ans int) { - sort.Ints(nums) - tree := newTrie() - i := 0 - for _, y := range nums { - tree.insert(y) - for ; y > nums[i]*2; i++ { - tree.remove(nums[i]) - } - ans = max(ans, tree.search(y)) - } - return ans +type Trie struct { + children [2]*Trie + cnt int +} + +func newTrie() *Trie { + return &Trie{} +} + +func (t *Trie) insert(x int) { + node := t + for i := 20; i >= 0; i-- { + v := (x >> uint(i)) & 1 + if node.children[v] == nil { + node.children[v] = newTrie() + } + node = node.children[v] + node.cnt++ + } +} + +func (t *Trie) search(x int) int { + node := t + ans := 0 + for i := 20; i >= 0; i-- { + v := (x >> uint(i)) & 1 + if node.children[v^1] != nil && node.children[v^1].cnt > 0 { + ans |= 1 << uint(i) + node = node.children[v^1] + } else { + node = node.children[v] + } + } + return ans +} + +func (t *Trie) remove(x int) { + node := t + for i := 20; i >= 0; i-- { + v := (x >> uint(i)) & 1 + node = node.children[v] + node.cnt-- + } +} + +func maximumStrongPairXor(nums []int) (ans int) { + sort.Ints(nums) + tree := newTrie() + i := 0 + for _, y := range nums { + tree.insert(y) + for ; y > nums[i]*2; i++ { + tree.remove(nums[i]) + } + ans = max(ans, tree.search(y)) + } + return ans } \ No newline at end of file diff --git a/solution/2900-2999/2941.Maximum GCD-Sum of a Subarray/Solution.go b/solution/2900-2999/2941.Maximum GCD-Sum of a Subarray/Solution.go index 00e638618ed40..7cb2781adb058 100644 --- a/solution/2900-2999/2941.Maximum GCD-Sum of a Subarray/Solution.go +++ b/solution/2900-2999/2941.Maximum GCD-Sum of a Subarray/Solution.go @@ -1,37 +1,37 @@ -func maxGcdSum(nums []int, k int) int64 { - n := len(nums) - s := make([]int64, n+1) - s[0] = 0 - for i, x := range nums { - s[i+1] = s[i] + int64(x) - } - type pair [2]int - var f []pair - var ans int64 - for i := 0; i < n; i++ { - var g []pair - for _, p := range f { - j, x := p[0], p[1] - y := int(gcd(int(x), nums[i])) - if len(g) == 0 || g[len(g)-1][1] != y { - g = append(g, pair{j, y}) - } - } - f = g - f = append(f, pair{i, nums[i]}) - for _, p := range f { - j, x := p[0], p[1] - if i-j+1 >= k { - ans = max(ans, (s[i+1]-s[j])*int64(x)) - } - } - } - return ans -} - -func gcd(a, b int) int { - if b == 0 { - return a - } - return gcd(b, a%b) +func maxGcdSum(nums []int, k int) int64 { + n := len(nums) + s := make([]int64, n+1) + s[0] = 0 + for i, x := range nums { + s[i+1] = s[i] + int64(x) + } + type pair [2]int + var f []pair + var ans int64 + for i := 0; i < n; i++ { + var g []pair + for _, p := range f { + j, x := p[0], p[1] + y := int(gcd(int(x), nums[i])) + if len(g) == 0 || g[len(g)-1][1] != y { + g = append(g, pair{j, y}) + } + } + f = g + f = append(f, pair{i, nums[i]}) + for _, p := range f { + j, x := p[0], p[1] + if i-j+1 >= k { + ans = max(ans, (s[i+1]-s[j])*int64(x)) + } + } + } + return ans +} + +func gcd(a, b int) int { + if b == 0 { + return a + } + return gcd(b, a%b) } \ No newline at end of file diff --git a/solution/2900-2999/2943.Maximize Area of Square Hole in Grid/Solution.go b/solution/2900-2999/2943.Maximize Area of Square Hole in Grid/Solution.go index cc82e4dd3fca8..bf231e090acdb 100644 --- a/solution/2900-2999/2943.Maximize Area of Square Hole in Grid/Solution.go +++ b/solution/2900-2999/2943.Maximize Area of Square Hole in Grid/Solution.go @@ -1,17 +1,17 @@ -func maximizeSquareHoleArea(n int, m int, hBars []int, vBars []int) int { - f := func(nums []int) int { - sort.Ints(nums) - ans, cnt := 1, 1 - for i, x := range nums[1:] { - if x == nums[i]+1 { - cnt++ - ans = max(ans, cnt) - } else { - cnt = 1 - } - } - return ans + 1 - } - x := min(f(hBars), f(vBars)) - return x * x +func maximizeSquareHoleArea(n int, m int, hBars []int, vBars []int) int { + f := func(nums []int) int { + sort.Ints(nums) + ans, cnt := 1, 1 + for i, x := range nums[1:] { + if x == nums[i]+1 { + cnt++ + ans = max(ans, cnt) + } else { + cnt = 1 + } + } + return ans + 1 + } + x := min(f(hBars), f(vBars)) + return x * x } \ No newline at end of file diff --git a/solution/2900-2999/2944.Minimum Number of Coins for Fruits/Solution.go b/solution/2900-2999/2944.Minimum Number of Coins for Fruits/Solution.go index 96c58608fb567..b51f1408db690 100644 --- a/solution/2900-2999/2944.Minimum Number of Coins for Fruits/Solution.go +++ b/solution/2900-2999/2944.Minimum Number of Coins for Fruits/Solution.go @@ -1,75 +1,75 @@ -func minimumCoins(prices []int) int { - n := len(prices) - q := Deque{} - for i := n; i > 0; i-- { - for q.Size() > 0 && q.Front() > i*2+1 { - q.PopFront() - } - if i <= (n-1)/2 { - prices[i-1] += prices[q.Front()-1] - } - for q.Size() > 0 && prices[q.Back()-1] >= prices[i-1] { - q.PopBack() - } - q.PushBack(i) - } - return prices[0] -} - -// template -type Deque struct{ l, r []int } - -func (q Deque) Empty() bool { - return len(q.l) == 0 && len(q.r) == 0 -} - -func (q Deque) Size() int { - return len(q.l) + len(q.r) -} - -func (q *Deque) PushFront(v int) { - q.l = append(q.l, v) -} - -func (q *Deque) PushBack(v int) { - q.r = append(q.r, v) -} - -func (q *Deque) PopFront() (v int) { - if len(q.l) > 0 { - q.l, v = q.l[:len(q.l)-1], q.l[len(q.l)-1] - } else { - v, q.r = q.r[0], q.r[1:] - } - return -} - -func (q *Deque) PopBack() (v int) { - if len(q.r) > 0 { - q.r, v = q.r[:len(q.r)-1], q.r[len(q.r)-1] - } else { - v, q.l = q.l[0], q.l[1:] - } - return -} - -func (q Deque) Front() int { - if len(q.l) > 0 { - return q.l[len(q.l)-1] - } - return q.r[0] -} - -func (q Deque) Back() int { - if len(q.r) > 0 { - return q.r[len(q.r)-1] - } - return q.l[0] -} - -func (q Deque) Get(i int) int { - if i < len(q.l) { - return q.l[len(q.l)-1-i] - } - return q.r[i-len(q.l)] +func minimumCoins(prices []int) int { + n := len(prices) + q := Deque{} + for i := n; i > 0; i-- { + for q.Size() > 0 && q.Front() > i*2+1 { + q.PopFront() + } + if i <= (n-1)/2 { + prices[i-1] += prices[q.Front()-1] + } + for q.Size() > 0 && prices[q.Back()-1] >= prices[i-1] { + q.PopBack() + } + q.PushBack(i) + } + return prices[0] +} + +// template +type Deque struct{ l, r []int } + +func (q Deque) Empty() bool { + return len(q.l) == 0 && len(q.r) == 0 +} + +func (q Deque) Size() int { + return len(q.l) + len(q.r) +} + +func (q *Deque) PushFront(v int) { + q.l = append(q.l, v) +} + +func (q *Deque) PushBack(v int) { + q.r = append(q.r, v) +} + +func (q *Deque) PopFront() (v int) { + if len(q.l) > 0 { + q.l, v = q.l[:len(q.l)-1], q.l[len(q.l)-1] + } else { + v, q.r = q.r[0], q.r[1:] + } + return +} + +func (q *Deque) PopBack() (v int) { + if len(q.r) > 0 { + q.r, v = q.r[:len(q.r)-1], q.r[len(q.r)-1] + } else { + v, q.l = q.l[0], q.l[1:] + } + return +} + +func (q Deque) Front() int { + if len(q.l) > 0 { + return q.l[len(q.l)-1] + } + return q.r[0] +} + +func (q Deque) Back() int { + if len(q.r) > 0 { + return q.r[len(q.r)-1] + } + return q.l[0] +} + +func (q Deque) Get(i int) int { + if i < len(q.l) { + return q.l[len(q.l)-1-i] + } + return q.r[i-len(q.l)] } \ No newline at end of file diff --git a/solution/2900-2999/2945.Find Maximum Non-decreasing Array Length/Solution.go b/solution/2900-2999/2945.Find Maximum Non-decreasing Array Length/Solution.go index 919fb79c815a8..e67ca8e6a00ad 100644 --- a/solution/2900-2999/2945.Find Maximum Non-decreasing Array Length/Solution.go +++ b/solution/2900-2999/2945.Find Maximum Non-decreasing Array Length/Solution.go @@ -1,16 +1,16 @@ -func findMaximumLength(nums []int) int { - n := len(nums) - f := make([]int, n+1) - pre := make([]int, n+2) - s := make([]int, n+1) - for i, x := range nums { - s[i+1] = s[i] + x - } - for i := 1; i <= n; i++ { - pre[i] = max(pre[i], pre[i-1]) - f[i] = f[pre[i]] + 1 - j := sort.SearchInts(s, s[i]*2-s[pre[i]]) - pre[j] = max(pre[j], i) - } - return f[n] +func findMaximumLength(nums []int) int { + n := len(nums) + f := make([]int, n+1) + pre := make([]int, n+2) + s := make([]int, n+1) + for i, x := range nums { + s[i+1] = s[i] + x + } + for i := 1; i <= n; i++ { + pre[i] = max(pre[i], pre[i-1]) + f[i] = f[pre[i]] + 1 + j := sort.SearchInts(s, s[i]*2-s[pre[i]]) + pre[j] = max(pre[j], i) + } + return f[n] } \ No newline at end of file diff --git a/solution/2900-2999/2946.Matrix Similarity After Cyclic Shifts/Solution.go b/solution/2900-2999/2946.Matrix Similarity After Cyclic Shifts/Solution.go index f3f1a4d147af2..8e617891da3a4 100644 --- a/solution/2900-2999/2946.Matrix Similarity After Cyclic Shifts/Solution.go +++ b/solution/2900-2999/2946.Matrix Similarity After Cyclic Shifts/Solution.go @@ -1,15 +1,15 @@ -func areSimilar(mat [][]int, k int) bool { - n := len(mat[0]) - k %= n - for i, row := range mat { - for j, x := range row { - if i%2 == 1 && x != mat[i][(j+k)%n] { - return false - } - if i%2 == 0 && x != mat[i][(j-k+n)%n] { - return false - } - } - } - return true +func areSimilar(mat [][]int, k int) bool { + n := len(mat[0]) + k %= n + for i, row := range mat { + for j, x := range row { + if i%2 == 1 && x != mat[i][(j+k)%n] { + return false + } + if i%2 == 0 && x != mat[i][(j-k+n)%n] { + return false + } + } + } + return true } \ No newline at end of file diff --git a/solution/2900-2999/2947.Count Beautiful Substrings I/Solution.go b/solution/2900-2999/2947.Count Beautiful Substrings I/Solution.go index 2f9deebad8a58..94580d83cd349 100644 --- a/solution/2900-2999/2947.Count Beautiful Substrings I/Solution.go +++ b/solution/2900-2999/2947.Count Beautiful Substrings I/Solution.go @@ -1,18 +1,18 @@ -func beautifulSubstrings(s string, k int) (ans int) { - n := len(s) - vs := [26]int{} - for _, c := range "aeiou" { - vs[c-'a'] = 1 - } - for i := 0; i < n; i++ { - vowels := 0 - for j := i; j < n; j++ { - vowels += vs[s[j]-'a'] - consonants := j - i + 1 - vowels - if vowels == consonants && vowels*consonants%k == 0 { - ans++ - } - } - } - return +func beautifulSubstrings(s string, k int) (ans int) { + n := len(s) + vs := [26]int{} + for _, c := range "aeiou" { + vs[c-'a'] = 1 + } + for i := 0; i < n; i++ { + vowels := 0 + for j := i; j < n; j++ { + vowels += vs[s[j]-'a'] + consonants := j - i + 1 - vowels + if vowels == consonants && vowels*consonants%k == 0 { + ans++ + } + } + } + return } \ No newline at end of file diff --git a/solution/2900-2999/2948.Make Lexicographically Smallest Array by Swapping Elements/Solution.go b/solution/2900-2999/2948.Make Lexicographically Smallest Array by Swapping Elements/Solution.go index ec2d4074d5f81..a249ee384cd20 100644 --- a/solution/2900-2999/2948.Make Lexicographically Smallest Array by Swapping Elements/Solution.go +++ b/solution/2900-2999/2948.Make Lexicographically Smallest Array by Swapping Elements/Solution.go @@ -1,22 +1,22 @@ -func lexicographicallySmallestArray(nums []int, limit int) []int { - n := len(nums) - idx := make([]int, n) - for i := range idx { - idx[i] = i - } - slices.SortFunc(idx, func(i, j int) int { return nums[i] - nums[j] }) - ans := make([]int, n) - for i := 0; i < n; { - j := i + 1 - for j < n && nums[idx[j]]-nums[idx[j-1]] <= limit { - j++ - } - t := slices.Clone(idx[i:j]) - slices.Sort(t) - for k := i; k < j; k++ { - ans[t[k-i]] = nums[idx[k]] - } - i = j - } - return ans +func lexicographicallySmallestArray(nums []int, limit int) []int { + n := len(nums) + idx := make([]int, n) + for i := range idx { + idx[i] = i + } + slices.SortFunc(idx, func(i, j int) int { return nums[i] - nums[j] }) + ans := make([]int, n) + for i := 0; i < n; { + j := i + 1 + for j < n && nums[idx[j]]-nums[idx[j-1]] <= limit { + j++ + } + t := slices.Clone(idx[i:j]) + slices.Sort(t) + for k := i; k < j; k++ { + ans[t[k-i]] = nums[idx[k]] + } + i = j + } + return ans } \ No newline at end of file diff --git a/solution/2900-2999/2954.Count the Number of Infection Sequences/Solution.go b/solution/2900-2999/2954.Count the Number of Infection Sequences/Solution.go index 502c31fcae283..4ace693e6d682 100644 --- a/solution/2900-2999/2954.Count the Number of Infection Sequences/Solution.go +++ b/solution/2900-2999/2954.Count the Number of Infection Sequences/Solution.go @@ -1,51 +1,51 @@ -const MX = 1e5 -const MOD = 1e9 + 7 - -var fac [MX + 1]int - -func init() { - fac[0] = 1 - for i := 1; i <= MX; i++ { - fac[i] = fac[i-1] * i % MOD - } -} - -func qpow(a, n int) int { - ans := 1 - for n > 0 { - if n&1 == 1 { - ans = (ans * a) % MOD - } - a = (a * a) % MOD - n >>= 1 - } - return ans -} - -func numberOfSequence(n int, sick []int) int { - m := len(sick) - nums := make([]int, m+1) - - nums[0] = sick[0] - nums[m] = n - sick[m-1] - 1 - for i := 1; i < m; i++ { - nums[i] = sick[i] - sick[i-1] - 1 - } - - s := 0 - for _, x := range nums { - s += x - } - ans := fac[s] - for _, x := range nums { - if x > 0 { - ans = ans * qpow(fac[x], MOD-2) % MOD - } - } - for i := 1; i < len(nums)-1; i++ { - if nums[i] > 1 { - ans = ans * qpow(2, nums[i]-1) % MOD - } - } - return ans +const MX = 1e5 +const MOD = 1e9 + 7 + +var fac [MX + 1]int + +func init() { + fac[0] = 1 + for i := 1; i <= MX; i++ { + fac[i] = fac[i-1] * i % MOD + } +} + +func qpow(a, n int) int { + ans := 1 + for n > 0 { + if n&1 == 1 { + ans = (ans * a) % MOD + } + a = (a * a) % MOD + n >>= 1 + } + return ans +} + +func numberOfSequence(n int, sick []int) int { + m := len(sick) + nums := make([]int, m+1) + + nums[0] = sick[0] + nums[m] = n - sick[m-1] - 1 + for i := 1; i < m; i++ { + nums[i] = sick[i] - sick[i-1] - 1 + } + + s := 0 + for _, x := range nums { + s += x + } + ans := fac[s] + for _, x := range nums { + if x > 0 { + ans = ans * qpow(fac[x], MOD-2) % MOD + } + } + for i := 1; i < len(nums)-1; i++ { + if nums[i] > 1 { + ans = ans * qpow(2, nums[i]-1) % MOD + } + } + return ans } \ No newline at end of file diff --git a/solution/2900-2999/2955.Number of Same-End Substrings/Solution.go b/solution/2900-2999/2955.Number of Same-End Substrings/Solution.go index 707c6758f0f14..9be14c9f1dae4 100644 --- a/solution/2900-2999/2955.Number of Same-End Substrings/Solution.go +++ b/solution/2900-2999/2955.Number of Same-End Substrings/Solution.go @@ -1,26 +1,26 @@ -func sameEndSubstringCount(s string, queries [][]int) []int { - n := len(s) - cnt := make([][]int, 26) - for i := 0; i < 26; i++ { - cnt[i] = make([]int, n+1) - } - - for j := 1; j <= n; j++ { - for i := 0; i < 26; i++ { - cnt[i][j] = cnt[i][j-1] - } - cnt[s[j-1]-'a'][j]++ - } - - var ans []int - for _, q := range queries { - l, r := q[0], q[1] - ans = append(ans, r-l+1) - for i := 0; i < 26; i++ { - x := cnt[i][r+1] - cnt[i][l] - ans[len(ans)-1] += x * (x - 1) / 2 - } - } - - return ans +func sameEndSubstringCount(s string, queries [][]int) []int { + n := len(s) + cnt := make([][]int, 26) + for i := 0; i < 26; i++ { + cnt[i] = make([]int, n+1) + } + + for j := 1; j <= n; j++ { + for i := 0; i < 26; i++ { + cnt[i][j] = cnt[i][j-1] + } + cnt[s[j-1]-'a'][j]++ + } + + var ans []int + for _, q := range queries { + l, r := q[0], q[1] + ans = append(ans, r-l+1) + for i := 0; i < 26; i++ { + x := cnt[i][r+1] - cnt[i][l] + ans[len(ans)-1] += x * (x - 1) / 2 + } + } + + return ans } \ No newline at end of file diff --git a/solution/2900-2999/2959.Number of Possible Sets of Closing Branches/Solution.go b/solution/2900-2999/2959.Number of Possible Sets of Closing Branches/Solution.go index ee20f387dde2d..037ce201ee639 100644 --- a/solution/2900-2999/2959.Number of Possible Sets of Closing Branches/Solution.go +++ b/solution/2900-2999/2959.Number of Possible Sets of Closing Branches/Solution.go @@ -1,38 +1,38 @@ -func numberOfSets(n int, maxDistance int, roads [][]int) (ans int) { - for mask := 0; mask < 1<>u&1 == 1 && mask>>v&1 == 1 { - g[u][v] = min(g[u][v], w) - g[v][u] = min(g[v][u], w) - } - } - for k := 0; k < n; k++ { - if mask>>k&1 == 1 { - g[k][k] = 0 - for i := 0; i < n; i++ { - for j := 0; j < n; j++ { - g[i][j] = min(g[i][j], g[i][k]+g[k][j]) - } - } - } - } - ok := 1 - for i := 0; i < n && ok == 1; i++ { - for j := 0; j < n && ok == 1; j++ { - if mask>>i&1 == 1 && mask>>j&1 == 1 && g[i][j] > maxDistance { - ok = 0 - } - } - } - ans += ok - } - return +func numberOfSets(n int, maxDistance int, roads [][]int) (ans int) { + for mask := 0; mask < 1<>u&1 == 1 && mask>>v&1 == 1 { + g[u][v] = min(g[u][v], w) + g[v][u] = min(g[v][u], w) + } + } + for k := 0; k < n; k++ { + if mask>>k&1 == 1 { + g[k][k] = 0 + for i := 0; i < n; i++ { + for j := 0; j < n; j++ { + g[i][j] = min(g[i][j], g[i][k]+g[k][j]) + } + } + } + } + ok := 1 + for i := 0; i < n && ok == 1; i++ { + for j := 0; j < n && ok == 1; j++ { + if mask>>i&1 == 1 && mask>>j&1 == 1 && g[i][j] > maxDistance { + ok = 0 + } + } + } + ans += ok + } + return } \ No newline at end of file diff --git a/solution/2900-2999/2960.Count Tested Devices After Test Operations/Solution.go b/solution/2900-2999/2960.Count Tested Devices After Test Operations/Solution.go index 6922458f5d15c..d9a666d81214f 100644 --- a/solution/2900-2999/2960.Count Tested Devices After Test Operations/Solution.go +++ b/solution/2900-2999/2960.Count Tested Devices After Test Operations/Solution.go @@ -1,9 +1,9 @@ -func countTestedDevices(batteryPercentages []int) (ans int) { - for _, x := range batteryPercentages { - x -= ans - if x > 0 { - ans++ - } - } - return +func countTestedDevices(batteryPercentages []int) (ans int) { + for _, x := range batteryPercentages { + x -= ans + if x > 0 { + ans++ + } + } + return } \ No newline at end of file diff --git a/solution/2900-2999/2961.Double Modular Exponentiation/Solution.go b/solution/2900-2999/2961.Double Modular Exponentiation/Solution.go index 483e2904ed7d5..9dc67f6df1e15 100644 --- a/solution/2900-2999/2961.Double Modular Exponentiation/Solution.go +++ b/solution/2900-2999/2961.Double Modular Exponentiation/Solution.go @@ -1,19 +1,19 @@ -func getGoodIndices(variables [][]int, target int) (ans []int) { - qpow := func(a, n, mod int) int { - ans := 1 - for ; n > 0; n >>= 1 { - if n&1 == 1 { - ans = ans * a % mod - } - a = a * a % mod - } - return ans - } - for i, e := range variables { - a, b, c, m := e[0], e[1], e[2], e[3] - if qpow(qpow(a, b, 10), c, m) == target { - ans = append(ans, i) - } - } - return +func getGoodIndices(variables [][]int, target int) (ans []int) { + qpow := func(a, n, mod int) int { + ans := 1 + for ; n > 0; n >>= 1 { + if n&1 == 1 { + ans = ans * a % mod + } + a = a * a % mod + } + return ans + } + for i, e := range variables { + a, b, c, m := e[0], e[1], e[2], e[3] + if qpow(qpow(a, b, 10), c, m) == target { + ans = append(ans, i) + } + } + return } \ No newline at end of file diff --git a/solution/2900-2999/2962.Count Subarrays Where Max Element Appears at Least K Times/Solution.go b/solution/2900-2999/2962.Count Subarrays Where Max Element Appears at Least K Times/Solution.go index 7f4030888cdb8..237bc370b9a85 100644 --- a/solution/2900-2999/2962.Count Subarrays Where Max Element Appears at Least K Times/Solution.go +++ b/solution/2900-2999/2962.Count Subarrays Where Max Element Appears at Least K Times/Solution.go @@ -1,20 +1,20 @@ -func countSubarrays(nums []int, k int) (ans int64) { - mx := slices.Max(nums) - n := len(nums) - cnt, j := 0, 0 - for _, x := range nums { - for ; j < n && cnt < k; j++ { - if nums[j] == mx { - cnt++ - } - } - if cnt < k { - break - } - ans += int64(n - j + 1) - if x == mx { - cnt-- - } - } - return +func countSubarrays(nums []int, k int) (ans int64) { + mx := slices.Max(nums) + n := len(nums) + cnt, j := 0, 0 + for _, x := range nums { + for ; j < n && cnt < k; j++ { + if nums[j] == mx { + cnt++ + } + } + if cnt < k { + break + } + ans += int64(n - j + 1) + if x == mx { + cnt-- + } + } + return } \ No newline at end of file diff --git a/solution/2900-2999/2963.Count the Number of Good Partitions/Solution.go b/solution/2900-2999/2963.Count the Number of Good Partitions/Solution.go index f732ff7dd37dc..0be498ec37fdf 100644 --- a/solution/2900-2999/2963.Count the Number of Good Partitions/Solution.go +++ b/solution/2900-2999/2963.Count the Number of Good Partitions/Solution.go @@ -1,25 +1,25 @@ -func numberOfGoodPartitions(nums []int) int { - qpow := func(a, n, mod int) int { - ans := 1 - for ; n > 0; n >>= 1 { - if n&1 == 1 { - ans = ans * a % mod - } - a = a * a % mod - } - return ans - } - last := map[int]int{} - for i, x := range nums { - last[x] = i - } - const mod int = 1e9 + 7 - j, k := -1, 0 - for i, x := range nums { - j = max(j, last[x]) - if i == j { - k++ - } - } - return qpow(2, k-1, mod) +func numberOfGoodPartitions(nums []int) int { + qpow := func(a, n, mod int) int { + ans := 1 + for ; n > 0; n >>= 1 { + if n&1 == 1 { + ans = ans * a % mod + } + a = a * a % mod + } + return ans + } + last := map[int]int{} + for i, x := range nums { + last[x] = i + } + const mod int = 1e9 + 7 + j, k := -1, 0 + for i, x := range nums { + j = max(j, last[x]) + if i == j { + k++ + } + } + return qpow(2, k-1, mod) } \ No newline at end of file diff --git a/solution/2900-2999/2964.Number of Divisible Triplet Sums/Solution.go b/solution/2900-2999/2964.Number of Divisible Triplet Sums/Solution.go index fbac7af154d23..7954e9ad12c5d 100644 --- a/solution/2900-2999/2964.Number of Divisible Triplet Sums/Solution.go +++ b/solution/2900-2999/2964.Number of Divisible Triplet Sums/Solution.go @@ -1,12 +1,12 @@ -func divisibleTripletCount(nums []int, d int) (ans int) { - n := len(nums) - cnt := map[int]int{} - for j := 0; j < n; j++ { - for k := j + 1; k < n; k++ { - x := (d - (nums[j]+nums[k])%d) % d - ans += cnt[x] - } - cnt[nums[j]%d]++ - } - return +func divisibleTripletCount(nums []int, d int) (ans int) { + n := len(nums) + cnt := map[int]int{} + for j := 0; j < n; j++ { + for k := j + 1; k < n; k++ { + x := (d - (nums[j]+nums[k])%d) % d + ans += cnt[x] + } + cnt[nums[j]%d]++ + } + return } \ No newline at end of file diff --git a/solution/2900-2999/2965.Find Missing and Repeated Values/Solution.go b/solution/2900-2999/2965.Find Missing and Repeated Values/Solution.go index 841abb696fdd2..8e1415c812e98 100644 --- a/solution/2900-2999/2965.Find Missing and Repeated Values/Solution.go +++ b/solution/2900-2999/2965.Find Missing and Repeated Values/Solution.go @@ -1,19 +1,19 @@ -func findMissingAndRepeatedValues(grid [][]int) []int { - n := len(grid) - ans := make([]int, 2) - cnt := make([]int, n*n+1) - for _, row := range grid { - for _, x := range row { - cnt[x]++ - if cnt[x] == 2 { - ans[0] = x - } - } - } - for x := 1; ; x++ { - if cnt[x] == 0 { - ans[1] = x - return ans - } - } +func findMissingAndRepeatedValues(grid [][]int) []int { + n := len(grid) + ans := make([]int, 2) + cnt := make([]int, n*n+1) + for _, row := range grid { + for _, x := range row { + cnt[x]++ + if cnt[x] == 2 { + ans[0] = x + } + } + } + for x := 1; ; x++ { + if cnt[x] == 0 { + ans[1] = x + return ans + } + } } \ No newline at end of file diff --git a/solution/2900-2999/2966.Divide Array Into Arrays With Max Difference/Solution.go b/solution/2900-2999/2966.Divide Array Into Arrays With Max Difference/Solution.go index d9ab6189f21bf..b5313d3effe70 100644 --- a/solution/2900-2999/2966.Divide Array Into Arrays With Max Difference/Solution.go +++ b/solution/2900-2999/2966.Divide Array Into Arrays With Max Difference/Solution.go @@ -1,12 +1,12 @@ -func divideArray(nums []int, k int) [][]int { - sort.Ints(nums) - ans := [][]int{} - for i := 0; i < len(nums); i += 3 { - t := slices.Clone(nums[i : i+3]) - if t[2]-t[0] > k { - return [][]int{} - } - ans = append(ans, t) - } - return ans +func divideArray(nums []int, k int) [][]int { + sort.Ints(nums) + ans := [][]int{} + for i := 0; i < len(nums); i += 3 { + t := slices.Clone(nums[i : i+3]) + if t[2]-t[0] > k { + return [][]int{} + } + ans = append(ans, t) + } + return ans } \ No newline at end of file diff --git a/solution/2900-2999/2967.Minimum Cost to Make Array Equalindromic/Solution.go b/solution/2900-2999/2967.Minimum Cost to Make Array Equalindromic/Solution.go index 3f6b36621dcbd..e746ee87339f3 100644 --- a/solution/2900-2999/2967.Minimum Cost to Make Array Equalindromic/Solution.go +++ b/solution/2900-2999/2967.Minimum Cost to Make Array Equalindromic/Solution.go @@ -1,52 +1,52 @@ -var ps [2 * 100000]int64 - -func init() { - for i := 1; i <= 100000; i++ { - s := strconv.Itoa(i) - t1 := reverseString(s) - t2 := reverseString(s[:len(s)-1]) - ps[2*i-2], _ = strconv.ParseInt(s+t1, 10, 64) - ps[2*i-1], _ = strconv.ParseInt(s+t2, 10, 64) - } - sort.Slice(ps[:], func(i, j int) bool { - return ps[i] < ps[j] - }) -} - -func reverseString(s string) string { - cs := []rune(s) - for i, j := 0, len(cs)-1; i < j; i, j = i+1, j-1 { - cs[i], cs[j] = cs[j], cs[i] - } - return string(cs) -} - -func minimumCost(nums []int) int64 { - sort.Ints(nums) - i := sort.Search(len(ps), func(i int) bool { - return ps[i] >= int64(nums[len(nums)/2]) - }) - - f := func(x int64) int64 { - var ans int64 - for _, v := range nums { - ans += int64(abs(int(x - int64(v)))) - } - return ans - } - - ans := int64(math.MaxInt64) - for j := i - 1; j <= i+1; j++ { - if 0 <= j && j < len(ps) { - ans = min(ans, f(ps[j])) - } - } - return ans -} - -func abs(x int) int { - if x < 0 { - return -x - } - return x +var ps [2 * 100000]int64 + +func init() { + for i := 1; i <= 100000; i++ { + s := strconv.Itoa(i) + t1 := reverseString(s) + t2 := reverseString(s[:len(s)-1]) + ps[2*i-2], _ = strconv.ParseInt(s+t1, 10, 64) + ps[2*i-1], _ = strconv.ParseInt(s+t2, 10, 64) + } + sort.Slice(ps[:], func(i, j int) bool { + return ps[i] < ps[j] + }) +} + +func reverseString(s string) string { + cs := []rune(s) + for i, j := 0, len(cs)-1; i < j; i, j = i+1, j-1 { + cs[i], cs[j] = cs[j], cs[i] + } + return string(cs) +} + +func minimumCost(nums []int) int64 { + sort.Ints(nums) + i := sort.Search(len(ps), func(i int) bool { + return ps[i] >= int64(nums[len(nums)/2]) + }) + + f := func(x int64) int64 { + var ans int64 + for _, v := range nums { + ans += int64(abs(int(x - int64(v)))) + } + return ans + } + + ans := int64(math.MaxInt64) + for j := i - 1; j <= i+1; j++ { + if 0 <= j && j < len(ps) { + ans = min(ans, f(ps[j])) + } + } + return ans +} + +func abs(x int) int { + if x < 0 { + return -x + } + return x } \ No newline at end of file diff --git a/solution/2900-2999/2968.Apply Operations to Maximize Frequency Score/Solution.go b/solution/2900-2999/2968.Apply Operations to Maximize Frequency Score/Solution.go index 1a54371c31360..da4f72a421c28 100644 --- a/solution/2900-2999/2968.Apply Operations to Maximize Frequency Score/Solution.go +++ b/solution/2900-2999/2968.Apply Operations to Maximize Frequency Score/Solution.go @@ -1,34 +1,34 @@ -func maxFrequencyScore(nums []int, k int64) int { - sort.Ints(nums) - n := len(nums) - s := make([]int64, n+1) - for i := 1; i <= n; i++ { - s[i] = s[i-1] + int64(nums[i-1]) - } - - l, r := 0, n - for l < r { - mid := (l + r + 1) >> 1 - ok := false - - for i := 0; i <= n-mid; i++ { - j := i + mid - x := int64(nums[(i+j)/2]) - left := (int64((i+j)/2-i) * x) - (s[(i+j)/2] - s[i]) - right := (s[j] - s[(i+j)/2]) - (int64(j-(i+j)/2) * x) - - if left+right <= k { - ok = true - break - } - } - - if ok { - l = mid - } else { - r = mid - 1 - } - } - - return l +func maxFrequencyScore(nums []int, k int64) int { + sort.Ints(nums) + n := len(nums) + s := make([]int64, n+1) + for i := 1; i <= n; i++ { + s[i] = s[i-1] + int64(nums[i-1]) + } + + l, r := 0, n + for l < r { + mid := (l + r + 1) >> 1 + ok := false + + for i := 0; i <= n-mid; i++ { + j := i + mid + x := int64(nums[(i+j)/2]) + left := (int64((i+j)/2-i) * x) - (s[(i+j)/2] - s[i]) + right := (s[j] - s[(i+j)/2]) - (int64(j-(i+j)/2) * x) + + if left+right <= k { + ok = true + break + } + } + + if ok { + l = mid + } else { + r = mid - 1 + } + } + + return l } \ No newline at end of file diff --git a/solution/2900-2999/2969.Minimum Number of Coins for Fruits II/Solution.go b/solution/2900-2999/2969.Minimum Number of Coins for Fruits II/Solution.go index 96c58608fb567..b51f1408db690 100644 --- a/solution/2900-2999/2969.Minimum Number of Coins for Fruits II/Solution.go +++ b/solution/2900-2999/2969.Minimum Number of Coins for Fruits II/Solution.go @@ -1,75 +1,75 @@ -func minimumCoins(prices []int) int { - n := len(prices) - q := Deque{} - for i := n; i > 0; i-- { - for q.Size() > 0 && q.Front() > i*2+1 { - q.PopFront() - } - if i <= (n-1)/2 { - prices[i-1] += prices[q.Front()-1] - } - for q.Size() > 0 && prices[q.Back()-1] >= prices[i-1] { - q.PopBack() - } - q.PushBack(i) - } - return prices[0] -} - -// template -type Deque struct{ l, r []int } - -func (q Deque) Empty() bool { - return len(q.l) == 0 && len(q.r) == 0 -} - -func (q Deque) Size() int { - return len(q.l) + len(q.r) -} - -func (q *Deque) PushFront(v int) { - q.l = append(q.l, v) -} - -func (q *Deque) PushBack(v int) { - q.r = append(q.r, v) -} - -func (q *Deque) PopFront() (v int) { - if len(q.l) > 0 { - q.l, v = q.l[:len(q.l)-1], q.l[len(q.l)-1] - } else { - v, q.r = q.r[0], q.r[1:] - } - return -} - -func (q *Deque) PopBack() (v int) { - if len(q.r) > 0 { - q.r, v = q.r[:len(q.r)-1], q.r[len(q.r)-1] - } else { - v, q.l = q.l[0], q.l[1:] - } - return -} - -func (q Deque) Front() int { - if len(q.l) > 0 { - return q.l[len(q.l)-1] - } - return q.r[0] -} - -func (q Deque) Back() int { - if len(q.r) > 0 { - return q.r[len(q.r)-1] - } - return q.l[0] -} - -func (q Deque) Get(i int) int { - if i < len(q.l) { - return q.l[len(q.l)-1-i] - } - return q.r[i-len(q.l)] +func minimumCoins(prices []int) int { + n := len(prices) + q := Deque{} + for i := n; i > 0; i-- { + for q.Size() > 0 && q.Front() > i*2+1 { + q.PopFront() + } + if i <= (n-1)/2 { + prices[i-1] += prices[q.Front()-1] + } + for q.Size() > 0 && prices[q.Back()-1] >= prices[i-1] { + q.PopBack() + } + q.PushBack(i) + } + return prices[0] +} + +// template +type Deque struct{ l, r []int } + +func (q Deque) Empty() bool { + return len(q.l) == 0 && len(q.r) == 0 +} + +func (q Deque) Size() int { + return len(q.l) + len(q.r) +} + +func (q *Deque) PushFront(v int) { + q.l = append(q.l, v) +} + +func (q *Deque) PushBack(v int) { + q.r = append(q.r, v) +} + +func (q *Deque) PopFront() (v int) { + if len(q.l) > 0 { + q.l, v = q.l[:len(q.l)-1], q.l[len(q.l)-1] + } else { + v, q.r = q.r[0], q.r[1:] + } + return +} + +func (q *Deque) PopBack() (v int) { + if len(q.r) > 0 { + q.r, v = q.r[:len(q.r)-1], q.r[len(q.r)-1] + } else { + v, q.l = q.l[0], q.l[1:] + } + return +} + +func (q Deque) Front() int { + if len(q.l) > 0 { + return q.l[len(q.l)-1] + } + return q.r[0] +} + +func (q Deque) Back() int { + if len(q.r) > 0 { + return q.r[len(q.r)-1] + } + return q.l[0] +} + +func (q Deque) Get(i int) int { + if i < len(q.l) { + return q.l[len(q.l)-1-i] + } + return q.r[i-len(q.l)] } \ No newline at end of file diff --git a/solution/2900-2999/2970.Count the Number of Incremovable Subarrays I/Solution.go b/solution/2900-2999/2970.Count the Number of Incremovable Subarrays I/Solution.go index 33781e82e6a37..3f2ba2578b999 100644 --- a/solution/2900-2999/2970.Count the Number of Incremovable Subarrays I/Solution.go +++ b/solution/2900-2999/2970.Count the Number of Incremovable Subarrays I/Solution.go @@ -1,20 +1,20 @@ -func incremovableSubarrayCount(nums []int) int { - i, n := 0, len(nums) - for i+1 < n && nums[i] < nums[i+1] { - i++ - } - if i == n-1 { - return n * (n + 1) / 2 - } - ans := i + 2 - for j := n - 1; j > 0; j-- { - for i >= 0 && nums[i] >= nums[j] { - i-- - } - ans += i + 2 - if nums[j-1] >= nums[j] { - break - } - } - return ans +func incremovableSubarrayCount(nums []int) int { + i, n := 0, len(nums) + for i+1 < n && nums[i] < nums[i+1] { + i++ + } + if i == n-1 { + return n * (n + 1) / 2 + } + ans := i + 2 + for j := n - 1; j > 0; j-- { + for i >= 0 && nums[i] >= nums[j] { + i-- + } + ans += i + 2 + if nums[j-1] >= nums[j] { + break + } + } + return ans } \ No newline at end of file diff --git a/solution/2900-2999/2971.Find Polygon With the Largest Perimeter/Solution.go b/solution/2900-2999/2971.Find Polygon With the Largest Perimeter/Solution.go index 37784766c196c..5411b4e80a3eb 100644 --- a/solution/2900-2999/2971.Find Polygon With the Largest Perimeter/Solution.go +++ b/solution/2900-2999/2971.Find Polygon With the Largest Perimeter/Solution.go @@ -1,15 +1,15 @@ -func largestPerimeter(nums []int) int64 { - sort.Ints(nums) - n := len(nums) - s := make([]int, n+1) - for i, x := range nums { - s[i+1] = s[i] + x - } - ans := -1 - for k := 3; k <= n; k++ { - if s[k-1] > nums[k-1] { - ans = max(ans, s[k]) - } - } - return int64(ans) +func largestPerimeter(nums []int) int64 { + sort.Ints(nums) + n := len(nums) + s := make([]int, n+1) + for i, x := range nums { + s[i+1] = s[i] + x + } + ans := -1 + for k := 3; k <= n; k++ { + if s[k-1] > nums[k-1] { + ans = max(ans, s[k]) + } + } + return int64(ans) } \ No newline at end of file diff --git a/solution/2900-2999/2972.Count the Number of Incremovable Subarrays II/Solution.go b/solution/2900-2999/2972.Count the Number of Incremovable Subarrays II/Solution.go index 873d8084933f3..19577a30c0cd7 100644 --- a/solution/2900-2999/2972.Count the Number of Incremovable Subarrays II/Solution.go +++ b/solution/2900-2999/2972.Count the Number of Incremovable Subarrays II/Solution.go @@ -1,20 +1,20 @@ -func incremovableSubarrayCount(nums []int) int64 { - i, n := 0, len(nums) - for i+1 < n && nums[i] < nums[i+1] { - i++ - } - if i == n-1 { - return int64(n * (n + 1) / 2) - } - ans := int64(i + 2) - for j := n - 1; j > 0; j-- { - for i >= 0 && nums[i] >= nums[j] { - i-- - } - ans += int64(i + 2) - if nums[j-1] >= nums[j] { - break - } - } - return ans +func incremovableSubarrayCount(nums []int) int64 { + i, n := 0, len(nums) + for i+1 < n && nums[i] < nums[i+1] { + i++ + } + if i == n-1 { + return int64(n * (n + 1) / 2) + } + ans := int64(i + 2) + for j := n - 1; j > 0; j-- { + for i >= 0 && nums[i] >= nums[j] { + i-- + } + ans += int64(i + 2) + if nums[j-1] >= nums[j] { + break + } + } + return ans } \ No newline at end of file diff --git a/solution/2900-2999/2973.Find Number of Coins to Place in Tree Nodes/Solution.go b/solution/2900-2999/2973.Find Number of Coins to Place in Tree Nodes/Solution.go index 86cf0651424b8..759d931eb6624 100644 --- a/solution/2900-2999/2973.Find Number of Coins to Place in Tree Nodes/Solution.go +++ b/solution/2900-2999/2973.Find Number of Coins to Place in Tree Nodes/Solution.go @@ -1,35 +1,35 @@ -func placedCoins(edges [][]int, cost []int) []int64 { - n := len(cost) - g := make([][]int, n) - for _, e := range edges { - a, b := e[0], e[1] - g[a] = append(g[a], b) - g[b] = append(g[b], a) - } - ans := make([]int64, n) - for i := range ans { - ans[i] = int64(1) - } - var dfs func(a, fa int) []int - dfs = func(a, fa int) []int { - res := []int{cost[a]} - for _, b := range g[a] { - if b != fa { - res = append(res, dfs(b, a)...) - } - } - sort.Ints(res) - m := len(res) - if m >= 3 { - x := res[m-1] * res[m-2] * res[m-3] - y := res[0] * res[1] * res[m-1] - ans[a] = max(0, int64(x), int64(y)) - } - if m >= 5 { - res = append(res[:2], res[m-3:]...) - } - return res - } - dfs(0, -1) - return ans +func placedCoins(edges [][]int, cost []int) []int64 { + n := len(cost) + g := make([][]int, n) + for _, e := range edges { + a, b := e[0], e[1] + g[a] = append(g[a], b) + g[b] = append(g[b], a) + } + ans := make([]int64, n) + for i := range ans { + ans[i] = int64(1) + } + var dfs func(a, fa int) []int + dfs = func(a, fa int) []int { + res := []int{cost[a]} + for _, b := range g[a] { + if b != fa { + res = append(res, dfs(b, a)...) + } + } + sort.Ints(res) + m := len(res) + if m >= 3 { + x := res[m-1] * res[m-2] * res[m-3] + y := res[0] * res[1] * res[m-1] + ans[a] = max(0, int64(x), int64(y)) + } + if m >= 5 { + res = append(res[:2], res[m-3:]...) + } + return res + } + dfs(0, -1) + return ans } \ No newline at end of file diff --git a/solution/2900-2999/2975.Maximum Square Area by Removing Fences From a Field/Solution.go b/solution/2900-2999/2975.Maximum Square Area by Removing Fences From a Field/Solution.go index e846acbca8034..177b458b1aaef 100644 --- a/solution/2900-2999/2975.Maximum Square Area by Removing Fences From a Field/Solution.go +++ b/solution/2900-2999/2975.Maximum Square Area by Removing Fences From a Field/Solution.go @@ -1,25 +1,25 @@ -func maximizeSquareArea(m int, n int, hFences []int, vFences []int) int { - f := func(nums []int, k int) map[int]bool { - nums = append(nums, 1, k) - sort.Ints(nums) - s := map[int]bool{} - for i := 0; i < len(nums); i++ { - for j := 0; j < i; j++ { - s[nums[i]-nums[j]] = true - } - } - return s - } - hs := f(hFences, m) - vs := f(vFences, n) - ans := 0 - for h := range hs { - if vs[h] { - ans = max(ans, h) - } - } - if ans > 0 { - return ans * ans % (1e9 + 7) - } - return -1 +func maximizeSquareArea(m int, n int, hFences []int, vFences []int) int { + f := func(nums []int, k int) map[int]bool { + nums = append(nums, 1, k) + sort.Ints(nums) + s := map[int]bool{} + for i := 0; i < len(nums); i++ { + for j := 0; j < i; j++ { + s[nums[i]-nums[j]] = true + } + } + return s + } + hs := f(hFences, m) + vs := f(vFences, n) + ans := 0 + for h := range hs { + if vs[h] { + ans = max(ans, h) + } + } + if ans > 0 { + return ans * ans % (1e9 + 7) + } + return -1 } \ No newline at end of file diff --git a/solution/2900-2999/2977.Minimum Cost to Convert String II/Solution.go b/solution/2900-2999/2977.Minimum Cost to Convert String II/Solution.go index ef741f5903197..db99dd6319d84 100644 --- a/solution/2900-2999/2977.Minimum Cost to Convert String II/Solution.go +++ b/solution/2900-2999/2977.Minimum Cost to Convert String II/Solution.go @@ -1,89 +1,89 @@ -type Node struct { - children [26]*Node - v int -} - -func newNode() *Node { - return &Node{v: -1} -} - -func minimumCost(source string, target string, original []string, changed []string, cost []int) int64 { - inf := 1 << 60 - root := newNode() - idx := 0 - m := len(cost) - g := make([][]int, m<<1) - for i := range g { - g[i] = make([]int, m<<1) - for j := range g[i] { - g[i][j] = inf - } - g[i][i] = 0 - } - insert := func(w string) int { - node := root - for _, c := range w { - i := c - 'a' - if node.children[i] == nil { - node.children[i] = newNode() - } - node = node.children[i] - } - if node.v < 0 { - node.v = idx - idx++ - } - return node.v - } - for i := range original { - x := insert(original[i]) - y := insert(changed[i]) - g[x][y] = min(g[x][y], cost[i]) - } - for k := 0; k < idx; k++ { - for i := 0; i < idx; i++ { - if g[i][k] >= inf { - continue - } - for j := 0; j < idx; j++ { - g[i][j] = min(g[i][j], g[i][k]+g[k][j]) - } - } - } - n := len(source) - f := make([]int, n) - for i := range f { - f[i] = -1 - } - var dfs func(int) int - dfs = func(i int) int { - if i >= n { - return 0 - } - if f[i] >= 0 { - return f[i] - } - f[i] = inf - if source[i] == target[i] { - f[i] = dfs(i + 1) - } - p, q := root, root - for j := i; j < n; j++ { - p = p.children[source[j]-'a'] - q = q.children[target[j]-'a'] - if p == nil || q == nil { - break - } - if p.v < 0 || q.v < 0 { - continue - } - f[i] = min(f[i], dfs(j+1)+g[p.v][q.v]) - } - return f[i] - } - ans := dfs(0) - if ans >= inf { - ans = -1 - } - return int64(ans) +type Node struct { + children [26]*Node + v int +} + +func newNode() *Node { + return &Node{v: -1} +} + +func minimumCost(source string, target string, original []string, changed []string, cost []int) int64 { + inf := 1 << 60 + root := newNode() + idx := 0 + m := len(cost) + g := make([][]int, m<<1) + for i := range g { + g[i] = make([]int, m<<1) + for j := range g[i] { + g[i][j] = inf + } + g[i][i] = 0 + } + insert := func(w string) int { + node := root + for _, c := range w { + i := c - 'a' + if node.children[i] == nil { + node.children[i] = newNode() + } + node = node.children[i] + } + if node.v < 0 { + node.v = idx + idx++ + } + return node.v + } + for i := range original { + x := insert(original[i]) + y := insert(changed[i]) + g[x][y] = min(g[x][y], cost[i]) + } + for k := 0; k < idx; k++ { + for i := 0; i < idx; i++ { + if g[i][k] >= inf { + continue + } + for j := 0; j < idx; j++ { + g[i][j] = min(g[i][j], g[i][k]+g[k][j]) + } + } + } + n := len(source) + f := make([]int, n) + for i := range f { + f[i] = -1 + } + var dfs func(int) int + dfs = func(i int) int { + if i >= n { + return 0 + } + if f[i] >= 0 { + return f[i] + } + f[i] = inf + if source[i] == target[i] { + f[i] = dfs(i + 1) + } + p, q := root, root + for j := i; j < n; j++ { + p = p.children[source[j]-'a'] + q = q.children[target[j]-'a'] + if p == nil || q == nil { + break + } + if p.v < 0 || q.v < 0 { + continue + } + f[i] = min(f[i], dfs(j+1)+g[p.v][q.v]) + } + return f[i] + } + ans := dfs(0) + if ans >= inf { + ans = -1 + } + return int64(ans) } \ No newline at end of file diff --git a/solution/2900-2999/2979.Most Expensive Item That Can Not Be Bought/Solution.go b/solution/2900-2999/2979.Most Expensive Item That Can Not Be Bought/Solution.go index 43f87480dcaba..a1bd69bb58d73 100644 --- a/solution/2900-2999/2979.Most Expensive Item That Can Not Be Bought/Solution.go +++ b/solution/2900-2999/2979.Most Expensive Item That Can Not Be Bought/Solution.go @@ -1,3 +1,3 @@ -func mostExpensiveItem(primeOne int, primeTwo int) int { - return primeOne*primeTwo - primeOne - primeTwo +func mostExpensiveItem(primeOne int, primeTwo int) int { + return primeOne*primeTwo - primeOne - primeTwo } \ No newline at end of file diff --git a/solution/2900-2999/2980.Check if Bitwise OR Has Trailing Zeros/Solution.go b/solution/2900-2999/2980.Check if Bitwise OR Has Trailing Zeros/Solution.go index 34a95bbedd24e..16c3d89a2d8d5 100644 --- a/solution/2900-2999/2980.Check if Bitwise OR Has Trailing Zeros/Solution.go +++ b/solution/2900-2999/2980.Check if Bitwise OR Has Trailing Zeros/Solution.go @@ -1,7 +1,7 @@ -func hasTrailingZeros(nums []int) bool { - cnt := 0 - for _, x := range nums { - cnt += (x&1 ^ 1) - } - return cnt >= 2 +func hasTrailingZeros(nums []int) bool { + cnt := 0 + for _, x := range nums { + cnt += (x&1 ^ 1) + } + return cnt >= 2 } \ No newline at end of file diff --git a/solution/2900-2999/2981.Find Longest Special Substring That Occurs Thrice I/Solution.go b/solution/2900-2999/2981.Find Longest Special Substring That Occurs Thrice I/Solution.go index 94a47b6b03c98..3995deefe943d 100644 --- a/solution/2900-2999/2981.Find Longest Special Substring That Occurs Thrice I/Solution.go +++ b/solution/2900-2999/2981.Find Longest Special Substring That Occurs Thrice I/Solution.go @@ -1,32 +1,32 @@ -func maximumLength(s string) int { - n := len(s) - l, r := 0, n - check := func(x int) bool { - cnt := [26]int{} - for i := 0; i < n; { - j := i + 1 - for j < n && s[j] == s[i] { - j++ - } - k := s[i] - 'a' - cnt[k] += max(0, j-i-x+1) - if cnt[k] >= 3 { - return true - } - i = j - } - return false - } - for l < r { - mid := (l + r + 1) >> 1 - if check(mid) { - l = mid - } else { - r = mid - 1 - } - } - if l == 0 { - return -1 - } - return l +func maximumLength(s string) int { + n := len(s) + l, r := 0, n + check := func(x int) bool { + cnt := [26]int{} + for i := 0; i < n; { + j := i + 1 + for j < n && s[j] == s[i] { + j++ + } + k := s[i] - 'a' + cnt[k] += max(0, j-i-x+1) + if cnt[k] >= 3 { + return true + } + i = j + } + return false + } + for l < r { + mid := (l + r + 1) >> 1 + if check(mid) { + l = mid + } else { + r = mid - 1 + } + } + if l == 0 { + return -1 + } + return l } \ No newline at end of file diff --git a/solution/2900-2999/2982.Find Longest Special Substring That Occurs Thrice II/Solution.go b/solution/2900-2999/2982.Find Longest Special Substring That Occurs Thrice II/Solution.go index 94a47b6b03c98..3995deefe943d 100644 --- a/solution/2900-2999/2982.Find Longest Special Substring That Occurs Thrice II/Solution.go +++ b/solution/2900-2999/2982.Find Longest Special Substring That Occurs Thrice II/Solution.go @@ -1,32 +1,32 @@ -func maximumLength(s string) int { - n := len(s) - l, r := 0, n - check := func(x int) bool { - cnt := [26]int{} - for i := 0; i < n; { - j := i + 1 - for j < n && s[j] == s[i] { - j++ - } - k := s[i] - 'a' - cnt[k] += max(0, j-i-x+1) - if cnt[k] >= 3 { - return true - } - i = j - } - return false - } - for l < r { - mid := (l + r + 1) >> 1 - if check(mid) { - l = mid - } else { - r = mid - 1 - } - } - if l == 0 { - return -1 - } - return l +func maximumLength(s string) int { + n := len(s) + l, r := 0, n + check := func(x int) bool { + cnt := [26]int{} + for i := 0; i < n; { + j := i + 1 + for j < n && s[j] == s[i] { + j++ + } + k := s[i] - 'a' + cnt[k] += max(0, j-i-x+1) + if cnt[k] >= 3 { + return true + } + i = j + } + return false + } + for l < r { + mid := (l + r + 1) >> 1 + if check(mid) { + l = mid + } else { + r = mid - 1 + } + } + if l == 0 { + return -1 + } + return l } \ No newline at end of file diff --git a/solution/2900-2999/2983.Palindrome Rearrangement Queries/Solution.go b/solution/2900-2999/2983.Palindrome Rearrangement Queries/Solution.go index 19021041471ac..1a47d334829d3 100644 --- a/solution/2900-2999/2983.Palindrome Rearrangement Queries/Solution.go +++ b/solution/2900-2999/2983.Palindrome Rearrangement Queries/Solution.go @@ -1,79 +1,79 @@ -func canMakePalindromeQueries(s string, queries [][]int) (ans []bool) { - n := len(s) - m := n / 2 - t := reverse(s[m:]) - s = s[:m] - - pre1 := make([][]int, m+1) - pre2 := make([][]int, m+1) - diff := make([]int, m+1) - pre1[0] = make([]int, 26) - pre2[0] = make([]int, 26) - - for i := 1; i <= m; i++ { - pre1[i] = slices.Clone(pre1[i-1]) - pre2[i] = slices.Clone(pre2[i-1]) - pre1[i][int(s[i-1]-'a')]++ - pre2[i][int(t[i-1]-'a')]++ - diff[i] = diff[i-1] - if s[i-1] != t[i-1] { - diff[i]++ - } - } - for _, q := range queries { - a, b := q[0], q[1] - c, d := n-1-q[3], n-1-q[2] - if a <= c { - ans = append(ans, check(pre1, pre2, diff, a, b, c, d)) - } else { - ans = append(ans, check(pre2, pre1, diff, c, d, a, b)) - } - } - return -} - -func check(pre1, pre2 [][]int, diff []int, a, b, c, d int) bool { - if diff[a] > 0 || diff[len(diff)-1]-diff[max(b, d)+1] > 0 { - return false - } - - if d <= b { - return slices.Equal(count(pre1, a, b), count(pre2, a, b)) - } - - if b < c { - return diff[c]-diff[b+1] == 0 && slices.Equal(count(pre1, a, b), count(pre2, a, b)) && slices.Equal(count(pre1, c, d), count(pre2, c, d)) - } - - cnt1 := sub(count(pre1, a, b), count(pre2, a, c-1)) - cnt2 := sub(count(pre2, c, d), count(pre1, b+1, d)) - - return !slices.Equal(cnt1, []int{}) && !slices.Equal(cnt2, []int{}) && slices.Equal(cnt1, cnt2) -} - -func count(pre [][]int, i, j int) []int { - cnt := make([]int, 26) - for k := 0; k < 26; k++ { - cnt[k] = pre[j+1][k] - pre[i][k] - } - return cnt -} - -func sub(cnt1, cnt2 []int) []int { - cnt := make([]int, 26) - for i := 0; i < 26; i++ { - cnt[i] = cnt1[i] - cnt2[i] - if cnt[i] < 0 { - return []int{} - } - } - return cnt -} - -func reverse(s string) string { - runes := []rune(s) - for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 { - runes[i], runes[j] = runes[j], runes[i] - } - return string(runes) +func canMakePalindromeQueries(s string, queries [][]int) (ans []bool) { + n := len(s) + m := n / 2 + t := reverse(s[m:]) + s = s[:m] + + pre1 := make([][]int, m+1) + pre2 := make([][]int, m+1) + diff := make([]int, m+1) + pre1[0] = make([]int, 26) + pre2[0] = make([]int, 26) + + for i := 1; i <= m; i++ { + pre1[i] = slices.Clone(pre1[i-1]) + pre2[i] = slices.Clone(pre2[i-1]) + pre1[i][int(s[i-1]-'a')]++ + pre2[i][int(t[i-1]-'a')]++ + diff[i] = diff[i-1] + if s[i-1] != t[i-1] { + diff[i]++ + } + } + for _, q := range queries { + a, b := q[0], q[1] + c, d := n-1-q[3], n-1-q[2] + if a <= c { + ans = append(ans, check(pre1, pre2, diff, a, b, c, d)) + } else { + ans = append(ans, check(pre2, pre1, diff, c, d, a, b)) + } + } + return +} + +func check(pre1, pre2 [][]int, diff []int, a, b, c, d int) bool { + if diff[a] > 0 || diff[len(diff)-1]-diff[max(b, d)+1] > 0 { + return false + } + + if d <= b { + return slices.Equal(count(pre1, a, b), count(pre2, a, b)) + } + + if b < c { + return diff[c]-diff[b+1] == 0 && slices.Equal(count(pre1, a, b), count(pre2, a, b)) && slices.Equal(count(pre1, c, d), count(pre2, c, d)) + } + + cnt1 := sub(count(pre1, a, b), count(pre2, a, c-1)) + cnt2 := sub(count(pre2, c, d), count(pre1, b+1, d)) + + return !slices.Equal(cnt1, []int{}) && !slices.Equal(cnt2, []int{}) && slices.Equal(cnt1, cnt2) +} + +func count(pre [][]int, i, j int) []int { + cnt := make([]int, 26) + for k := 0; k < 26; k++ { + cnt[k] = pre[j+1][k] - pre[i][k] + } + return cnt +} + +func sub(cnt1, cnt2 []int) []int { + cnt := make([]int, 26) + for i := 0; i < 26; i++ { + cnt[i] = cnt1[i] - cnt2[i] + if cnt[i] < 0 { + return []int{} + } + } + return cnt +} + +func reverse(s string) string { + runes := []rune(s) + for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 { + runes[i], runes[j] = runes[j], runes[i] + } + return string(runes) } \ No newline at end of file diff --git a/solution/2900-2999/2984.Find Peak Calling Hours for Each City/README.md b/solution/2900-2999/2984.Find Peak Calling Hours for Each City/README.md index 2624c26c22677..bedfe3109fb25 100644 --- a/solution/2900-2999/2984.Find Peak Calling Hours for Each City/README.md +++ b/solution/2900-2999/2984.Find Peak Calling Hours for Each City/README.md @@ -1,4 +1,4 @@ -# [2984. Find Peak Calling Hours for Each City](https://leetcode.cn/problems/find-peak-calling-hours-for-each-city) +# [2984. 找到每座城市的高峰通话时间](https://leetcode.cn/problems/find-peak-calling-hours-for-each-city) [English Version](/solution/2900-2999/2984.Find%20Peak%20Calling%20Hours%20for%20Each%20City/README_EN.md) @@ -6,7 +6,7 @@ -

Table: Calls

+

表: Calls

 +--------------+----------+
@@ -17,21 +17,22 @@
 | call_time    | datetime |
 | city         | varchar  |
 +--------------+----------+
-(caller_id, recipient_id, call_time) is the primary key (combination of columns with unique values) for this table.
-Each row contains caller id, recipient id, call time, and city.
+(caller_id, recipient_id, call_time) 是该表的主键(具有唯一值的列)。
+每一行包含 caller id, recipient id, call time,和 city。
 
-

Write a solution to find the peak calling hour for each city. If multiple hours have the same number of calls, all of those hours will be recognized as peak hours for that specific city.

+

编写一个查询,找到每个 city 的 高峰 通话 时间。如果 多个时间 有 相同 数量的通话,则所有这些时间都将被视为该特定城市的 高峰时间

-

Return the result table ordered by peak calling hour and city in descending order.

+

按照 高峰通话时间 和 city 降序 排序返回结果表。

-

The result format is in the following example.

+

结果格式如下例所示。

 

-

Example 1:

+ +

示例 1:

-Input: 
+输入:
 Calls table:
 +-----------+--------------+---------------------+----------+
 | caller_id | recipient_id | call_time           | city     |
@@ -43,7 +44,7 @@ Calls table:
 | 11        | 3            | 2021-08-17 13:07:00 | New York |
 | 8         | 11           | 2021-08-17 14:22:22 | New York |
 +-----------+--------------+---------------------+----------+
-Output: 
+输出:
 +----------+-------------------+-----------------+
 | city     | peak_calling_hour | number_of_calls |
 +----------+-------------------+-----------------+
@@ -51,12 +52,12 @@ Calls table:
 | New York | 14                | 1               |
 | New York | 13                | 1               |
 +----------+-------------------+-----------------+
-Explanation: 
-For Houston:
-  - The peak time is 22:00, with a total of 3 calls recorded. 
-For New York:
-  - Both 13:00 and 14:00 hours have equal call counts of 1, so both times are considered peak hours.
-Output table is ordered by peak_calling_hour and city in descending order.
+解释: +对于 Houston: + - 高峰时间是 22:00,总共记录了 3 次通话。 +对于 New York: + - 3:00 和 14:00 都有相同数量的通话,因此这两个时间都被视为高峰小时。 +输出表按照高峰通话小时和城市按降序排序。 ## 解法 diff --git a/solution/2900-2999/2985.Calculate Compressed Mean/README.md b/solution/2900-2999/2985.Calculate Compressed Mean/README.md index 4ebe00dd687a5..0af0a5c3afb61 100644 --- a/solution/2900-2999/2985.Calculate Compressed Mean/README.md +++ b/solution/2900-2999/2985.Calculate Compressed Mean/README.md @@ -1,4 +1,4 @@ -# [2985. Calculate Compressed Mean](https://leetcode.cn/problems/calculate-compressed-mean) +# [2985. 计算订单平均商品数量](https://leetcode.cn/problems/calculate-compressed-mean) [English Version](/solution/2900-2999/2985.Calculate%20Compressed%20Mean/README_EN.md) @@ -6,7 +6,7 @@ -

Table: Orders

+

表: Orders

 +-------------------+------+
@@ -16,21 +16,22 @@
 | item_count        | int  |
 | order_occurrences | int  |
 +-------------------+------+
-order_id is column of unique values for this table.
-This table contains order_id, item_count, and order_occurrences.
+order_id 是这张表具有唯一值的列。
+这张表包括 order_id, item_count,和 order_occurrences。
 
-

Write a solution to calculate the average number of items per order, rounded to 2 decimal places.

+

编写一个计算每个订单的 平均 商品数量的解决方案,保留 2 位小数。

-

Return the result table in any order.

+

 任意 顺序返回结果表。

-

The result format is in the following example.

+

结果格式如下例所示。

 

-

Example 1:

+ +

示例 1:

-Input: 
+输入:
 Orders table:
 +----------+------------+-------------------+
 | order_id | item_count | order_occurrences | 
@@ -40,17 +41,18 @@ Orders table:
 | 12       | 3          | 800               |  
 | 13       | 4          | 1000              | 
 +----------+------------+-------------------+
-Output
+输出
 +-------------------------+
 | average_items_per_order | 
 +-------------------------+
 | 2.70                    |
 +-------------------------+
-Explanation
-The calculation is as follows:
- - Total items: (1 * 500) + (2 * 1000) + (3 * 800) + (4 * 1000) = 8900 
- - Total orders: 500 + 1000 + 800 + 1000 = 3300 
- - Therefore, the average items per order is 8900 / 3300 = 2.70
+解释 +计算如下: + - 总商品数:(1 * 500) + (2 * 1000) + (3 * 800) + (4 * 1000) = 8900 + - 总订单数:500 + 1000 + 800 + 1000 = 3300 + - 因此,每个订单的平均商品数量为 8900 / 3300 = 2.70 + ## 解法 diff --git a/solution/2900-2999/2986.Find Third Transaction/README.md b/solution/2900-2999/2986.Find Third Transaction/README.md index d60ca000b0cc6..9292c8765d4b3 100644 --- a/solution/2900-2999/2986.Find Third Transaction/README.md +++ b/solution/2900-2999/2986.Find Third Transaction/README.md @@ -1,4 +1,4 @@ -# [2986. Find Third Transaction](https://leetcode.cn/problems/find-third-transaction) +# [2986. 找到第三笔交易](https://leetcode.cn/problems/find-third-transaction) [English Version](/solution/2900-2999/2986.Find%20Third%20Transaction/README_EN.md) @@ -6,7 +6,7 @@ -

Table: Transactions

+

表: Transactions

 +------------------+----------+
@@ -16,21 +16,22 @@
 | spend            | decimal  |
 | transaction_date | datetime |
 +------------------+----------+
-(user_id, transaction_date) is column of unique values for this table.
-This table contains user_id, spend, and transaction_date.
+(user_id, transaction_date) 是这张表具有唯一值的列。
+该表包含 user_id, spend,和 transaction_date。
 
-

Write a solution to find the third transaction (if they have at least three transactions) of every user, where the spending on the preceding two transactions is lower than the spending on the third transaction.

+

编写一个查询,找到每个用户的 第三笔交易 (如果他们有至少三笔交易),其中 前两笔交易 的花费 低于 第三笔交易的花费。

-

Return the result table by user_id in ascending order.

+

返回 升序 user_id 排序的结果表。

-

The result format is in the following example.

+

结果格式如下例所示。

 

-

Example 1:

+ +

示例 1:

-Input: 
+输入:
 Transactions table:
 +---------+--------+---------------------+
 | user_id | spend  | transaction_date    | 
@@ -45,17 +46,17 @@ Transactions table:
 | 3       | 13.89  | 2023-11-11 16:00:14 | 
 | 3       | 7.0    | 2023-11-29 22:32:36 | 
 +---------+--------+---------------------+
-Output
+输出
 +---------+-------------------------+------------------------+
 | user_id | third_transaction_spend | third_transaction_date | 
 +---------+-------------------------+------------------------+
 | 1       | 65.56                   | 2023-11-18 13:49:42    |  
 +---------+-------------------------+------------------------+
-Explanation
-- For user_id 1, their third transaction occurred on 2023-11-18 at 13:49:42 with an amount of $65.56, surpassing the expenditures of the previous two transactions which were $7.44 on 2023-11-02 at 12:15:23 and $49.78 on 2023-11-12 at 00:13:46. Thus, this third transaction will be included in the output table.
-- user_id 2 only has a total of 2 transactions, so there isn't a third transaction to consider.
-- For user_id 3, the amount of $7.0 for their third transaction is less than that of the preceding two transactions, so it won't be included.
-Output table is ordered by user_id in ascending order.
+解释
+- 对于 user_id 1,他们的第三笔交易发生在 2023-11-18 13:49:42,金额为 $65.56,超过了前两笔交易的支出,分别是 2023-11-02 12:15:23 的 $7.44 和 2023-11-12 00:13:46 的 $49.78。因此,此第三笔交易将包含在输出表中。
+- user_id 2 只有总共 2 笔交易,因此没有第三笔交易。
+- 对于 user_id 3,第三笔交易的金额 $7.0 少于前两笔交易,因此不会包含在内。
+输出表按升序按 user_id 排序。
 
 
diff --git a/solution/2900-2999/2987.Find Expensive Cities/README.md b/solution/2900-2999/2987.Find Expensive Cities/README.md index 8c1df66e3722f..a3d33d7308e89 100644 --- a/solution/2900-2999/2987.Find Expensive Cities/README.md +++ b/solution/2900-2999/2987.Find Expensive Cities/README.md @@ -1,4 +1,4 @@ -# [2987. Find Expensive Cities](https://leetcode.cn/problems/find-expensive-cities) +# [2987. 寻找房价最贵的城市](https://leetcode.cn/problems/find-expensive-cities) [English Version](/solution/2900-2999/2987.Find%20Expensive%20Cities/README_EN.md) @@ -6,7 +6,7 @@ -

Table: Listings

+

表: Listings

 +-------------+---------+
@@ -16,21 +16,22 @@
 | city        | varchar |
 | price       | int     |
 +-------------+---------+
-listing_id is column of unique values for this table.
-This table contains listing_id, city, and price.
+listing_id 是这张表具有唯一值的列。
+这张表包括 listing_id, city,和 price。
 
-

Write a solution to find cities where the average home prices exceed the national average home price.

+

编写一个解决方案,查找 房价平均值 超过 全国 平均房价的 城市

-

Return the result table sorted by city in ascending order.

+

返回 按 city 升序 排序的结果表。

-

The result format is in the following example.

+

结果格式如下例所示。

 

-

Example 1:

+ +

示例 1:

-Input: 
+输入:
 Listings table:
 +------------+--------------+---------+
 | listing_id | city         | price   | 
@@ -47,21 +48,20 @@ Listings table:
 | 51         | NewYork      | 5951718 | 
 | 121        | NewYork      | 2893760 | 
 +------------+--------------+---------+
-Output
+输出
 +------------+
 | city       | 
 +------------+
 | Chicago    | 
 | LosAngeles |  
 +------------+
-Explanation
-The national average home price is $6,122,059.45. Among the cities listed:
-- Chicago has an average price of $7,043,706.75
-- Los Angeles has an average price of $6,277,754.5
-- San Francisco has an average price of $3,900,513.33
-- New York has an average price of $4,422,739
-Only Chicago and Los Angeles have average home prices exceeding the national average. Therefore, these two cities are included in the output table. The output table is sorted in ascending order based on the city names.
-
+解释
+全国平均房价为 $6,122,059.45。在列出的城市中:
+- Chicago 的平均价格为 $7,043,706.75
+- Los Angeles 的平均价格为 $6,277,754.5
+- San Francisco 的平均价格为 $3,900,513.33
+- New York 的平均价格为 $4,422,739
+只有 Chicago 和 Los Angeles 的平均房价超过了全国平均水平。因此,这两个城市包含在输出表中。输出表按城市名称升序排序。
 
## 解法 diff --git a/solution/2900-2999/2988.Manager of the Largest Department/README.md b/solution/2900-2999/2988.Manager of the Largest Department/README.md index ed583464591d5..b5db68abf00e6 100644 --- a/solution/2900-2999/2988.Manager of the Largest Department/README.md +++ b/solution/2900-2999/2988.Manager of the Largest Department/README.md @@ -1,4 +1,4 @@ -# [2988. Manager of the Largest Department](https://leetcode.cn/problems/manager-of-the-largest-department) +# [2988. 最大部门的经理](https://leetcode.cn/problems/manager-of-the-largest-department) [English Version](/solution/2900-2999/2988.Manager%20of%20the%20Largest%20Department/README_EN.md) @@ -6,7 +6,7 @@ -

Table: Employees

+

表: Employees

 +-------------+---------+
@@ -17,21 +17,22 @@
 | dep_id      | int     |
 | position    | varchar |
 +-------------+---------+
-emp_id is column of unique values for this table.
-This table contains emp_id, emp_name, dep_id, and position.
+emp_id 是这张表具有唯一值的列。
+这张表包括 emp_id, emp_name, dep_id,和 position。
 
-

Write a solution to find the name of the manager from the largest department. There may be multiple largest departments when the number of employees in those departments is the same.

+

查询 最大部门 的 经理 的 名字。当拥有相同数量的员工时,可能会有多个最大部门。

-

Return the result table sorted by dep_id in ascending order.

+

返回 按照 dep_id 升序 排列的结果表格。

-

The result format is in the following example.

+

结果表格的格式如下例所示。

 

-

Example 1:

+ +

示例 1:

-Input: 
+输入:
 Employees table:
 +--------+----------+--------+---------------+
 | emp_id | emp_name | dep_id | position      | 
@@ -48,16 +49,16 @@ Employees table:
 | 128    | Ian      | 101    | Administrator |
 | 81     | Ethan    | 107    | Administrator |
 +--------+----------+--------+---------------+
-Output
+输出
 +--------------+--------+
 | manager_name | dep_id | 
 +--------------+--------+
 | Joseph       | 100    | 
 | Isabella     | 101    | 
 +--------------+--------+
-Explanation
-- Departments with IDs 100 and 101 each has a total of 4 employees, while department 107 has 3 employees. Since both departments 100 and 101 have an equal number of employees, their respective managers will be included.
-Output table is ordered by dep_id in ascending order.
+解释
+- 部门 ID 为 100 和 101 的每个部门都有 4 名员工,而部门 107 有 3 名员工。由于部门 100 和 101 都拥有相同数量的员工,它们各自的经理将被包括在内。
+输出表格按 dep_id 升序排列。
 
 
diff --git a/solution/2900-2999/2991.Top Three Wineries/README.md b/solution/2900-2999/2991.Top Three Wineries/README.md index 61f662623c882..b786dd6223d0b 100644 --- a/solution/2900-2999/2991.Top Three Wineries/README.md +++ b/solution/2900-2999/2991.Top Three Wineries/README.md @@ -1,4 +1,4 @@ -# [2991. Top Three Wineries](https://leetcode.cn/problems/top-three-wineries) +# [2991. 最好的三家酒庄](https://leetcode.cn/problems/top-three-wineries) [English Version](/solution/2900-2999/2991.Top%20Three%20Wineries/README_EN.md) @@ -6,7 +6,7 @@ -

Table: Wineries

+

表: Wineries

 +-------------+----------+
@@ -17,21 +17,22 @@
 | points      | int      |
 | winery      | varchar  |
 +-------------+----------+
-id is column of unique values for this table.
-This table contains id, country, points, and winery.
+id 是这张表具有唯一值的列。
+这张表包含 id, country, points,和 winery。
 
-

Write a solution to find the top three wineries in each country based on their total points. If multiple wineries have the same total points, order them by winery name in ascending order. If there's no second winery, output 'No Second Winery,' and if there's no third winery, output 'No Third Winery.'

+

编写一个查询来找到 每个国家前三家 基于它们的 总分数 酒庄。如果 多个酒庄 具有 相同 的总分数,则按 升序 排列它们的 winery 名称。如果 没有第二家酒庄,则输出 'No Second Winery',如果 没有第三家酒庄,则输出 'No Third Winery'。

-

Return the result table ordered by country in ascending order.

+

返回结果表按 country 升序 排列。

-

The result format is in the following example.

+

结果表格格式如下例所示。

 

-

Example 1:

+ +

示例 1:

-Input: 
+输入:
 Sessions table:
 +-----+-----------+--------+-----------------+
 | id  | country   | points | winery          | 
@@ -41,34 +42,34 @@ Sessions table:
 | 848 | Australia | 100    | HarmonyHill     | 
 | 222 | Hungary   | 60     | MoonlitCellars  | 
 | 116 | USA       | 47     | RoyalVines      | 
-| 124 | USA       | 45     | Eagle'sNest     | 
+| 124 | USA       | 45     | Eagle'sNest     | 
 | 648 | India     | 69     | SunsetVines     | 
 | 894 | USA       | 39     | RoyalVines      |  
 | 677 | USA       | 9      | PacificCrest    |  
 +-----+-----------+--------+-----------------+
-Output: 
+输出:
 +-----------+---------------------+-------------------+----------------------+
 | country   | top_winery          | second_winery     | third_winery         |
 +-----------+---------------------+-------------------+----------------------+
 | Australia | HarmonyHill (100)   | GrapesGalore (85) | WhisperingPines (84) |
 | Hungary   | MoonlitCellars (60) | No second winery  | No third winery      | 
 | India     | SunsetVines (69)    | No second winery  | No third winery      |  
-| USA       | RoyalVines (86)     | Eagle'sNest (45)  | PacificCrest (9)     | 
+| USA       | RoyalVines (86)     | Eagle'sNest (45)  | PacificCrest (9)     | 
 +-----------+---------------------+-------------------+----------------------+
-Explanation
-For Australia
- - HarmonyHill Winery accumulates the highest score of 100 points in Australia.
- - GrapesGalore Winery has a total of 85 points, securing the second-highest position in Australia.
- - WhisperingPines Winery has a total of 80 points, ranking as the third-highest.
-For Hungary
- - MoonlitCellars is the sole winery, accruing 60 points, automatically making it the highest. There is no second or third winery.
-For India
- - SunsetVines is the sole winery, earning 69 points, making it the top winery. There is no second or third winery.
-For the USA
- - RoyalVines Wines accumulates a total of 47 + 39 = 86 points, claiming the highest position in the USA.
- - Eagle'sNest has a total of 45 points, securing the second-highest position in the USA.
- - PacificCrest accumulates 9 points, ranking as the third-highest winery in the USA
-Output table is ordered by country in ascending order.
+解释:
+对于 Australia
+ - HarmonyHill 酒庄获得了 Australia 的最高分数,为 100 分。
+ - GrapesGalore 酒庄总共获得 85 分,位列 Australia 的第二位。
+ - WhisperingPines 酒庄总共获得 80 分,位列 Australia 的第三位。
+对于 Hungary
+ - MoonlitCellars 是唯一的酒庄,获得 60 分,自动成为最高分数的酒庄。没有第二或第三家酒庄。
+对于 India
+ - SunsetVines 是唯一的酒庄,获得 69 分,成为最高的酒庄。没有第二或第三家酒庄。
+对于 USA
+ - RoyalVines Wines 累计了总分 47 + 39 = 86 分,占据了 USA 的最高位置。
+ - Eagle'sNest 总共获得 45 分,位列 USA 的第二高位置。
+ - PacificCrest 累计了 9 分,位列 USA 的第三高酒庄。
+输出表按国家首字母升序排列。
 
## 解法 diff --git a/solution/2900-2999/2992.Number of Self-Divisible Permutations/README.md b/solution/2900-2999/2992.Number of Self-Divisible Permutations/README.md index 571460593765b..1c513ba3123d6 100644 --- a/solution/2900-2999/2992.Number of Self-Divisible Permutations/README.md +++ b/solution/2900-2999/2992.Number of Self-Divisible Permutations/README.md @@ -1,4 +1,4 @@ -# [2992. Number of Self-Divisible Permutations](https://leetcode.cn/problems/number-of-self-divisible-permutations) +# [2992. 自整除排列的数量](https://leetcode.cn/problems/number-of-self-divisible-permutations) [English Version](/solution/2900-2999/2992.Number%20of%20Self-Divisible%20Permutations/README_EN.md) @@ -6,16 +6,16 @@ -

Given an integer n, return the number of permutations of the 1-indexed array nums = [1, 2, ..., n], such that it's self-divisible.

+

给定一个整数 n,返回 下标从 1 开始 的数组 nums = [1, 2, ..., n]排列数,使其满足 自整除 条件。

-

Array nums is self-divisible if for every 1 <= i <= n, at least one of the following conditions holds:

+

如果对于每个 1 <= i <= n至少 满足以下条件之一,数组 nums 就是 自整除 的:

  • nums[i] % i == 0
  • i % nums[i] == 0
-

A permutation of an array is a rearrangement of the elements of that array, for example here are all of the permutations of the array [1, 2, 3]:

+

数组的 排列 是对数组元素的重新排列的数量,例如,下面是数组 [1, 2, 3] 的所有排列:

  • [1, 2, 3]
  • @@ -27,35 +27,37 @@

 

-

Example 1:

+ +

示例 1:

-Input: n = 1
-Output: 1
-Explanation: The array [1] has only 1 permutation which is self-divisible.
+输入:n = 1
+输出:1
+解释:数组 [1] 只有一个排列,它是自整除的。
 
-

Example 2:

+

示例 2:

-Input: n = 2
-Output: 2
-Explanation: The array [1,2] has 2 permutations both of which are self-divisible:
-nums = [1,2]: This is self-divisible since nums[1] % 1 == 0 and nums[2] % 2 == 0.
-nums = [2,1]: This is self-divisible since nums[1] % 1 == 0 and 2 % nums[2] == 0.
+输入:n = 2
+输出:2
+解释:数组 [1,2] 有 2 个排列,都是自整除的:
+nums = [1,2]:这是自整除的,因为 nums[1] % 1 == 0 和 nums[2] % 2 == 0。
+nums = [2,1]:这是自整除的,因为 nums[1] % 1 == 0 和 2 % nums[2] == 0。
 
-

Example 3:

+

示例 3:

-Input: n = 3
-Output: 3
-Explanation: The array [1,2,3] has 3 self-divisble permutations: [1,2,3], [2,1,3], [3,2,1].
-It can be shown that the other 3 permutations are not self-divisible. Hence the answer is 3.
+输入:n = 3
+输出:3
+解释:数组 [1,2,3] 有 3 个自整除的排列:[1,2,3]、[2,1,3]、[3,2,1]。
+其他 3 个排列不能满足自整除条件。因此答案是 3。
 

 

-

Constraints:

+ +

提示:

  • 1 <= n <= 15
  • diff --git a/solution/2900-2999/2992.Number of Self-Divisible Permutations/README_EN.md b/solution/2900-2999/2992.Number of Self-Divisible Permutations/README_EN.md index 85d596213d6c3..f4b64ac40370d 100644 --- a/solution/2900-2999/2992.Number of Self-Divisible Permutations/README_EN.md +++ b/solution/2900-2999/2992.Number of Self-Divisible Permutations/README_EN.md @@ -6,12 +6,7 @@

    Given an integer n, return the number of permutations of the 1-indexed array nums = [1, 2, ..., n], such that it's self-divisible.

    -

    Array nums is self-divisible if for every 1 <= i <= n, at least one of the following conditions holds:

    - -
      -
    • nums[i] % i == 0
    • -
    • i % nums[i] == 0
    • -
    +

    A 1-indexed array a of length n is self-divisible if for every 1 <= i <= n, gcd(a[i], i) == 1.

    A permutation of an array is a rearrangement of the elements of that array, for example here are all of the permutations of the array [1, 2, 3]:

    @@ -37,10 +32,10 @@
     Input: n = 2
    -Output: 2
    -Explanation: The array [1,2] has 2 permutations both of which are self-divisible:
    -nums = [1,2]: This is self-divisible since nums[1] % 1 == 0 and nums[2] % 2 == 0.
    -nums = [2,1]: This is self-divisible since nums[1] % 1 == 0 and 2 % nums[2] == 0.
    +Output: 1
    +Explanation: The array [1,2] has 2 permutations and only one of them is self-divisible:
    +nums = [1,2]: This is not self-divisible since gcd(nums[2], 2) != 1.
    +nums = [2,1]: This is self-divisible since gcd(nums[1], 1) == 1 and gcd(nums[2], 2) == 1.
     

    Example 3:

    @@ -48,7 +43,7 @@ nums = [2,1]: This is self-divisible since nums[1] % 1 == 0 and 2 % nums[2] == 0
     Input: n = 3
     Output: 3
    -Explanation: The array [1,2,3] has 3 self-divisble permutations: [1,2,3], [2,1,3], [3,2,1].
    +Explanation: The array [1,2,3] has 3 self-divisble permutations: [1,3,2], [3,1,2], [2,3,1].
     It can be shown that the other 3 permutations are not self-divisible. Hence the answer is 3.
     
    @@ -56,7 +51,7 @@ It can be shown that the other 3 permutations are not self-divisible. Hence the

    Constraints:

      -
    • 1 <= n <= 15
    • +
    • 1 <= n <= 12
    ## Solutions diff --git a/solution/README.md b/solution/README.md index 8514f544836cd..ba104a4c232a2 100644 --- a/solution/README.md +++ b/solution/README.md @@ -264,7 +264,7 @@ | 0251 | [展开二维向量](/solution/0200-0299/0251.Flatten%202D%20Vector/README.md) | `设计`,`数组`,`双指针`,`迭代器` | 中等 | 🔒 | | 0252 | [会议室](/solution/0200-0299/0252.Meeting%20Rooms/README.md) | `数组`,`排序` | 简单 | 🔒 | | 0253 | [会议室 II](/solution/0200-0299/0253.Meeting%20Rooms%20II/README.md) | `贪心`,`数组`,`双指针`,`前缀和`,`排序`,`堆(优先队列)` | 中等 | 🔒 | -| 0254 | [因子的组合](/solution/0200-0299/0254.Factor%20Combinations/README.md) | `数组`,`回溯` | 中等 | 🔒 | +| 0254 | [因子的组合](/solution/0200-0299/0254.Factor%20Combinations/README.md) | `回溯` | 中等 | 🔒 | | 0255 | [验证二叉搜索树的前序遍历序列](/solution/0200-0299/0255.Verify%20Preorder%20Sequence%20in%20Binary%20Search%20Tree/README.md) | `栈`,`树`,`二叉搜索树`,`递归`,`二叉树`,`单调栈` | 中等 | 🔒 | | 0256 | [粉刷房子](/solution/0200-0299/0256.Paint%20House/README.md) | `数组`,`动态规划` | 中等 | 🔒 | | 0257 | [二叉树的所有路径](/solution/0200-0299/0257.Binary%20Tree%20Paths/README.md) | `树`,`深度优先搜索`,`字符串`,`回溯`,`二叉树` | 简单 | | @@ -700,7 +700,7 @@ | 0687 | [最长同值路径](/solution/0600-0699/0687.Longest%20Univalue%20Path/README.md) | `树`,`深度优先搜索`,`二叉树` | 中等 | | | 0688 | [骑士在棋盘上的概率](/solution/0600-0699/0688.Knight%20Probability%20in%20Chessboard/README.md) | `动态规划` | 中等 | | | 0689 | [三个无重叠子数组的最大和](/solution/0600-0699/0689.Maximum%20Sum%20of%203%20Non-Overlapping%20Subarrays/README.md) | `数组`,`动态规划` | 困难 | | -| 0690 | [员工的重要性](/solution/0600-0699/0690.Employee%20Importance/README.md) | `深度优先搜索`,`广度优先搜索`,`哈希表` | 中等 | | +| 0690 | [员工的重要性](/solution/0600-0699/0690.Employee%20Importance/README.md) | `树`,`深度优先搜索`,`广度优先搜索`,`数组`,`哈希表` | 中等 | | | 0691 | [贴纸拼词](/solution/0600-0699/0691.Stickers%20to%20Spell%20Word/README.md) | `位运算`,`数组`,`字符串`,`动态规划`,`回溯`,`状态压缩` | 困难 | | | 0692 | [前K个高频单词](/solution/0600-0699/0692.Top%20K%20Frequent%20Words/README.md) | `字典树`,`哈希表`,`字符串`,`桶排序`,`计数`,`排序`,`堆(优先队列)` | 中等 | | | 0693 | [交替位二进制数](/solution/0600-0699/0693.Binary%20Number%20with%20Alternating%20Bits/README.md) | `位运算` | 简单 | | @@ -884,7 +884,7 @@ | 0871 | [最低加油次数](/solution/0800-0899/0871.Minimum%20Number%20of%20Refueling%20Stops/README.md) | `贪心`,`数组`,`动态规划`,`堆(优先队列)` | 困难 | 第 93 场周赛 | | 0872 | [叶子相似的树](/solution/0800-0899/0872.Leaf-Similar%20Trees/README.md) | `树`,`深度优先搜索`,`二叉树` | 简单 | 第 94 场周赛 | | 0873 | [最长的斐波那契子序列的长度](/solution/0800-0899/0873.Length%20of%20Longest%20Fibonacci%20Subsequence/README.md) | `数组`,`哈希表`,`动态规划` | 中等 | 第 94 场周赛 | -| 0874 | [模拟行走机器人](/solution/0800-0899/0874.Walking%20Robot%20Simulation/README.md) | `数组`,`模拟` | 中等 | 第 94 场周赛 | +| 0874 | [模拟行走机器人](/solution/0800-0899/0874.Walking%20Robot%20Simulation/README.md) | `数组`,`哈希表`,`模拟` | 中等 | 第 94 场周赛 | | 0875 | [爱吃香蕉的珂珂](/solution/0800-0899/0875.Koko%20Eating%20Bananas/README.md) | `数组`,`二分查找` | 中等 | 第 94 场周赛 | | 0876 | [链表的中间结点](/solution/0800-0899/0876.Middle%20of%20the%20Linked%20List/README.md) | `链表`,`双指针` | 简单 | 第 95 场周赛 | | 0877 | [石子游戏](/solution/0800-0899/0877.Stone%20Game/README.md) | `数组`,`数学`,`动态规划`,`博弈` | 中等 | 第 95 场周赛 | @@ -980,7 +980,7 @@ | 0967 | [连续差相同的数字](/solution/0900-0999/0967.Numbers%20With%20Same%20Consecutive%20Differences/README.md) | `广度优先搜索`,`回溯` | 中等 | 第 117 场周赛 | | 0968 | [监控二叉树](/solution/0900-0999/0968.Binary%20Tree%20Cameras/README.md) | `树`,`深度优先搜索`,`动态规划`,`二叉树` | 困难 | 第 117 场周赛 | | 0969 | [煎饼排序](/solution/0900-0999/0969.Pancake%20Sorting/README.md) | `贪心`,`数组`,`双指针`,`排序` | 中等 | 第 118 场周赛 | -| 0970 | [强整数](/solution/0900-0999/0970.Powerful%20Integers/README.md) | `哈希表`,`数学` | 中等 | 第 118 场周赛 | +| 0970 | [强整数](/solution/0900-0999/0970.Powerful%20Integers/README.md) | `哈希表`,`数学`,`枚举` | 中等 | 第 118 场周赛 | | 0971 | [翻转二叉树以匹配先序遍历](/solution/0900-0999/0971.Flip%20Binary%20Tree%20To%20Match%20Preorder%20Traversal/README.md) | `树`,`深度优先搜索`,`二叉树` | 中等 | 第 118 场周赛 | | 0972 | [相等的有理数](/solution/0900-0999/0972.Equal%20Rational%20Numbers/README.md) | `数学`,`字符串` | 困难 | 第 118 场周赛 | | 0973 | [最接近原点的 K 个点](/solution/0900-0999/0973.K%20Closest%20Points%20to%20Origin/README.md) | `几何`,`数组`,`数学`,`分治`,`快速选择`,`排序`,`堆(优先队列)` | 中等 | 第 119 场周赛 | @@ -1178,7 +1178,7 @@ | 1165 | [单行键盘](/solution/1100-1199/1165.Single-Row%20Keyboard/README.md) | `哈希表`,`字符串` | 简单 | 第 7 场双周赛 | | 1166 | [设计文件系统](/solution/1100-1199/1166.Design%20File%20System/README.md) | `设计`,`字典树`,`哈希表`,`字符串` | 中等 | 第 7 场双周赛 | | 1167 | [连接木棍的最低费用](/solution/1100-1199/1167.Minimum%20Cost%20to%20Connect%20Sticks/README.md) | `贪心`,`数组`,`堆(优先队列)` | 中等 | 第 7 场双周赛 | -| 1168 | [水资源分配优化](/solution/1100-1199/1168.Optimize%20Water%20Distribution%20in%20a%20Village/README.md) | `并查集`,`图`,`最小生成树` | 困难 | 第 7 场双周赛 | +| 1168 | [水资源分配优化](/solution/1100-1199/1168.Optimize%20Water%20Distribution%20in%20a%20Village/README.md) | `并查集`,`图`,`最小生成树`,`堆(优先队列)` | 困难 | 第 7 场双周赛 | | 1169 | [查询无效交易](/solution/1100-1199/1169.Invalid%20Transactions/README.md) | `数组`,`哈希表`,`字符串`,`排序` | 中等 | 第 151 场周赛 | | 1170 | [比较字符串最小字母出现频次](/solution/1100-1199/1170.Compare%20Strings%20by%20Frequency%20of%20the%20Smallest%20Character/README.md) | `数组`,`哈希表`,`字符串`,`二分查找`,`排序` | 中等 | 第 151 场周赛 | | 1171 | [从链表中删去总和值为零的连续节点](/solution/1100-1199/1171.Remove%20Zero%20Sum%20Consecutive%20Nodes%20from%20Linked%20List/README.md) | `哈希表`,`链表` | 中等 | 第 151 场周赛 | @@ -1432,7 +1432,7 @@ | 1419 | [数青蛙](/solution/1400-1499/1419.Minimum%20Number%20of%20Frogs%20Croaking/README.md) | `字符串`,`计数` | 中等 | 第 185 场周赛 | | 1420 | [生成数组](/solution/1400-1499/1420.Build%20Array%20Where%20You%20Can%20Find%20The%20Maximum%20Exactly%20K%20Comparisons/README.md) | `动态规划`,`前缀和` | 困难 | 第 185 场周赛 | | 1421 | [净现值查询](/solution/1400-1499/1421.NPV%20Queries/README.md) | `数据库` | 简单 | 🔒 | -| 1422 | [分割字符串的最大得分](/solution/1400-1499/1422.Maximum%20Score%20After%20Splitting%20a%20String/README.md) | `字符串` | 简单 | 第 186 场周赛 | +| 1422 | [分割字符串的最大得分](/solution/1400-1499/1422.Maximum%20Score%20After%20Splitting%20a%20String/README.md) | `字符串`,`前缀和` | 简单 | 第 186 场周赛 | | 1423 | [可获得的最大点数](/solution/1400-1499/1423.Maximum%20Points%20You%20Can%20Obtain%20from%20Cards/README.md) | `数组`,`前缀和`,`滑动窗口` | 中等 | 第 186 场周赛 | | 1424 | [对角线遍历 II](/solution/1400-1499/1424.Diagonal%20Traverse%20II/README.md) | `数组`,`排序`,`堆(优先队列)` | 中等 | 第 186 场周赛 | | 1425 | [带限制的子序列和](/solution/1400-1499/1425.Constrained%20Subsequence%20Sum/README.md) | `队列`,`数组`,`动态规划`,`滑动窗口`,`单调队列`,`堆(优先队列)` | 困难 | 第 186 场周赛 | @@ -1465,7 +1465,7 @@ | 1452 | [收藏清单](/solution/1400-1499/1452.People%20Whose%20List%20of%20Favorite%20Companies%20Is%20Not%20a%20Subset%20of%20Another%20List/README.md) | `数组`,`哈希表`,`字符串` | 中等 | 第 189 场周赛 | | 1453 | [圆形靶内的最大飞镖数量](/solution/1400-1499/1453.Maximum%20Number%20of%20Darts%20Inside%20of%20a%20Circular%20Dartboard/README.md) | `几何`,`数组`,`数学` | 困难 | 第 189 场周赛 | | 1454 | [活跃用户](/solution/1400-1499/1454.Active%20Users/README.md) | `数据库` | 中等 | 🔒 | -| 1455 | [检查单词是否为句中其他单词的前缀](/solution/1400-1499/1455.Check%20If%20a%20Word%20Occurs%20As%20a%20Prefix%20of%20Any%20Word%20in%20a%20Sentence/README.md) | `字符串`,`字符串匹配` | 简单 | 第 190 场周赛 | +| 1455 | [检查单词是否为句中其他单词的前缀](/solution/1400-1499/1455.Check%20If%20a%20Word%20Occurs%20As%20a%20Prefix%20of%20Any%20Word%20in%20a%20Sentence/README.md) | `双指针`,`字符串`,`字符串匹配` | 简单 | 第 190 场周赛 | | 1456 | [定长子串中元音的最大数目](/solution/1400-1499/1456.Maximum%20Number%20of%20Vowels%20in%20a%20Substring%20of%20Given%20Length/README.md) | `字符串`,`滑动窗口` | 中等 | 第 190 场周赛 | | 1457 | [二叉树中的伪回文路径](/solution/1400-1499/1457.Pseudo-Palindromic%20Paths%20in%20a%20Binary%20Tree/README.md) | `位运算`,`树`,`深度优先搜索`,`广度优先搜索`,`二叉树` | 中等 | 第 190 场周赛 | | 1458 | [两个子序列的最大点积](/solution/1400-1499/1458.Max%20Dot%20Product%20of%20Two%20Subsequences/README.md) | `数组`,`动态规划` | 困难 | 第 190 场周赛 | @@ -1631,7 +1631,7 @@ | 1618 | [找出适应屏幕的最大字号](/solution/1600-1699/1618.Maximum%20Font%20to%20Fit%20a%20Sentence%20in%20a%20Screen/README.md) | `数组`,`字符串`,`二分查找`,`交互` | 中等 | 🔒 | | 1619 | [删除某些元素后的数组均值](/solution/1600-1699/1619.Mean%20of%20Array%20After%20Removing%20Some%20Elements/README.md) | `数组`,`排序` | 简单 | 第 37 场双周赛 | | 1620 | [网络信号最好的坐标](/solution/1600-1699/1620.Coordinate%20With%20Maximum%20Network%20Quality/README.md) | `数组`,`枚举` | 中等 | 第 37 场双周赛 | -| 1621 | [大小为 K 的不重叠线段的数目](/solution/1600-1699/1621.Number%20of%20Sets%20of%20K%20Non-Overlapping%20Line%20Segments/README.md) | `数学`,`动态规划` | 中等 | 第 37 场双周赛 | +| 1621 | [大小为 K 的不重叠线段的数目](/solution/1600-1699/1621.Number%20of%20Sets%20of%20K%20Non-Overlapping%20Line%20Segments/README.md) | `数学`,`动态规划`,`组合数学` | 中等 | 第 37 场双周赛 | | 1622 | [奇妙序列](/solution/1600-1699/1622.Fancy%20Sequence/README.md) | `设计`,`线段树`,`数学` | 困难 | 第 37 场双周赛 | | 1623 | [三人国家代表队](/solution/1600-1699/1623.All%20Valid%20Triplets%20That%20Can%20Represent%20a%20Country/README.md) | `数据库` | 简单 | 🔒 | | 1624 | [两个相同字符之间的最长子字符串](/solution/1600-1699/1624.Largest%20Substring%20Between%20Two%20Equal%20Characters/README.md) | `哈希表`,`字符串` | 简单 | 第 211 场周赛 | @@ -1640,14 +1640,14 @@ | 1627 | [带阈值的图连通性](/solution/1600-1699/1627.Graph%20Connectivity%20With%20Threshold/README.md) | `并查集`,`数组`,`数学`,`数论` | 困难 | 第 211 场周赛 | | 1628 | [设计带解析函数的表达式树](/solution/1600-1699/1628.Design%20an%20Expression%20Tree%20With%20Evaluate%20Function/README.md) | `栈`,`树`,`设计`,`数学`,`二叉树` | 中等 | 🔒 | | 1629 | [按键持续时间最长的键](/solution/1600-1699/1629.Slowest%20Key/README.md) | `数组`,`字符串` | 简单 | 第 212 场周赛 | -| 1630 | [等差子数组](/solution/1600-1699/1630.Arithmetic%20Subarrays/README.md) | `数组`,`排序` | 中等 | 第 212 场周赛 | +| 1630 | [等差子数组](/solution/1600-1699/1630.Arithmetic%20Subarrays/README.md) | `数组`,`哈希表`,`排序` | 中等 | 第 212 场周赛 | | 1631 | [最小体力消耗路径](/solution/1600-1699/1631.Path%20With%20Minimum%20Effort/README.md) | `深度优先搜索`,`广度优先搜索`,`并查集`,`数组`,`二分查找`,`矩阵`,`堆(优先队列)` | 中等 | 第 212 场周赛 | | 1632 | [矩阵转换后的秩](/solution/1600-1699/1632.Rank%20Transform%20of%20a%20Matrix/README.md) | `并查集`,`图`,`拓扑排序`,`数组`,`矩阵`,`排序` | 困难 | 第 212 场周赛 | | 1633 | [各赛事的用户注册率](/solution/1600-1699/1633.Percentage%20of%20Users%20Attended%20a%20Contest/README.md) | `数据库` | 简单 | | | 1634 | [求两个多项式链表的和](/solution/1600-1699/1634.Add%20Two%20Polynomials%20Represented%20as%20Linked%20Lists/README.md) | `链表`,`数学`,`双指针` | 中等 | 🔒 | | 1635 | [Hopper 公司查询 I](/solution/1600-1699/1635.Hopper%20Company%20Queries%20I/README.md) | `数据库` | 困难 | 🔒 | | 1636 | [按照频率将数组升序排序](/solution/1600-1699/1636.Sort%20Array%20by%20Increasing%20Frequency/README.md) | `数组`,`哈希表`,`排序` | 简单 | 第 38 场双周赛 | -| 1637 | [两点之间不包含任何点的最宽垂直区域](/solution/1600-1699/1637.Widest%20Vertical%20Area%20Between%20Two%20Points%20Containing%20No%20Points/README.md) | `数组`,`排序` | 中等 | 第 38 场双周赛 | +| 1637 | [两点之间不包含任何点的最宽垂直区域](/solution/1600-1699/1637.Widest%20Vertical%20Area%20Between%20Two%20Points%20Containing%20No%20Points/README.md) | `数组`,`排序` | 简单 | 第 38 场双周赛 | | 1638 | [统计只差一个字符的子串数目](/solution/1600-1699/1638.Count%20Substrings%20That%20Differ%20by%20One%20Character/README.md) | `哈希表`,`字符串`,`动态规划` | 中等 | 第 38 场双周赛 | | 1639 | [通过给定词典构造目标字符串的方案数](/solution/1600-1699/1639.Number%20of%20Ways%20to%20Form%20a%20Target%20String%20Given%20a%20Dictionary/README.md) | `数组`,`字符串`,`动态规划` | 困难 | 第 38 场双周赛 | | 1640 | [能否连接形成数组](/solution/1600-1699/1640.Check%20Array%20Formation%20Through%20Concatenation/README.md) | `数组`,`哈希表` | 简单 | 第 213 场周赛 | @@ -1656,13 +1656,13 @@ | 1643 | [第 K 条最小指令](/solution/1600-1699/1643.Kth%20Smallest%20Instructions/README.md) | `数组`,`数学`,`动态规划`,`组合数学` | 困难 | 第 213 场周赛 | | 1644 | [二叉树的最近公共祖先 II](/solution/1600-1699/1644.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Tree%20II/README.md) | `树`,`深度优先搜索`,`二叉树` | 中等 | 🔒 | | 1645 | [Hopper 公司查询 II](/solution/1600-1699/1645.Hopper%20Company%20Queries%20II/README.md) | `数据库` | 困难 | 🔒 | -| 1646 | [获取生成数组中的最大值](/solution/1600-1699/1646.Get%20Maximum%20in%20Generated%20Array/README.md) | `数组`,`动态规划`,`模拟` | 简单 | 第 214 场周赛 | +| 1646 | [获取生成数组中的最大值](/solution/1600-1699/1646.Get%20Maximum%20in%20Generated%20Array/README.md) | `数组`,`模拟` | 简单 | 第 214 场周赛 | | 1647 | [字符频次唯一的最小删除次数](/solution/1600-1699/1647.Minimum%20Deletions%20to%20Make%20Character%20Frequencies%20Unique/README.md) | `贪心`,`哈希表`,`字符串`,`排序` | 中等 | 第 214 场周赛 | | 1648 | [销售价值减少的颜色球](/solution/1600-1699/1648.Sell%20Diminishing-Valued%20Colored%20Balls/README.md) | `贪心`,`数组`,`数学`,`二分查找`,`排序`,`堆(优先队列)` | 中等 | 第 214 场周赛 | | 1649 | [通过指令创建有序数组](/solution/1600-1699/1649.Create%20Sorted%20Array%20through%20Instructions/README.md) | `树状数组`,`线段树`,`数组`,`二分查找`,`分治`,`有序集合`,`归并排序` | 困难 | 第 214 场周赛 | | 1650 | [二叉树的最近公共祖先 III](/solution/1600-1699/1650.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Tree%20III/README.md) | `树`,`哈希表`,`双指针`,`二叉树` | 中等 | 🔒 | | 1651 | [Hopper 公司查询 III](/solution/1600-1699/1651.Hopper%20Company%20Queries%20III/README.md) | `数据库` | 困难 | 🔒 | -| 1652 | [拆炸弹](/solution/1600-1699/1652.Defuse%20the%20Bomb/README.md) | `数组` | 简单 | 第 39 场双周赛 | +| 1652 | [拆炸弹](/solution/1600-1699/1652.Defuse%20the%20Bomb/README.md) | `数组`,`滑动窗口` | 简单 | 第 39 场双周赛 | | 1653 | [使字符串平衡的最少删除次数](/solution/1600-1699/1653.Minimum%20Deletions%20to%20Make%20String%20Balanced/README.md) | `栈`,`字符串`,`动态规划` | 中等 | 第 39 场双周赛 | | 1654 | [到家的最少跳跃次数](/solution/1600-1699/1654.Minimum%20Jumps%20to%20Reach%20Home/README.md) | `广度优先搜索`,`数组`,`动态规划` | 中等 | 第 39 场双周赛 | | 1655 | [分配重复整数](/solution/1600-1699/1655.Distribute%20Repeating%20Integers/README.md) | `位运算`,`数组`,`动态规划`,`回溯`,`状态压缩` | 困难 | 第 39 场双周赛 | @@ -1736,14 +1736,14 @@ | 1723 | [完成所有工作的最短时间](/solution/1700-1799/1723.Find%20Minimum%20Time%20to%20Finish%20All%20Jobs/README.md) | `位运算`,`数组`,`动态规划`,`回溯`,`状态压缩` | 困难 | 第 223 场周赛 | | 1724 | [检查边长度限制的路径是否存在 II](/solution/1700-1799/1724.Checking%20Existence%20of%20Edge%20Length%20Limited%20Paths%20II/README.md) | `并查集`,`图`,`最小生成树` | 困难 | 🔒 | | 1725 | [可以形成最大正方形的矩形数目](/solution/1700-1799/1725.Number%20Of%20Rectangles%20That%20Can%20Form%20The%20Largest%20Square/README.md) | `数组` | 简单 | 第 224 场周赛 | -| 1726 | [同积元组](/solution/1700-1799/1726.Tuple%20with%20Same%20Product/README.md) | `数组`,`哈希表` | 中等 | 第 224 场周赛 | +| 1726 | [同积元组](/solution/1700-1799/1726.Tuple%20with%20Same%20Product/README.md) | `数组`,`哈希表`,`计数` | 中等 | 第 224 场周赛 | | 1727 | [重新排列后的最大子矩阵](/solution/1700-1799/1727.Largest%20Submatrix%20With%20Rearrangements/README.md) | `贪心`,`数组`,`矩阵`,`排序` | 中等 | 第 224 场周赛 | | 1728 | [猫和老鼠 II](/solution/1700-1799/1728.Cat%20and%20Mouse%20II/README.md) | `图`,`拓扑排序`,`记忆化搜索`,`数组`,`数学`,`动态规划`,`博弈`,`矩阵` | 困难 | 第 224 场周赛 | | 1729 | [求关注者的数量](/solution/1700-1799/1729.Find%20Followers%20Count/README.md) | `数据库` | 简单 | | | 1730 | [获取食物的最短路径](/solution/1700-1799/1730.Shortest%20Path%20to%20Get%20Food/README.md) | `广度优先搜索`,`数组`,`矩阵` | 中等 | 🔒 | | 1731 | [每位经理的下属员工数量](/solution/1700-1799/1731.The%20Number%20of%20Employees%20Which%20Report%20to%20Each%20Employee/README.md) | `数据库` | 简单 | | | 1732 | [找到最高海拔](/solution/1700-1799/1732.Find%20the%20Highest%20Altitude/README.md) | `数组`,`前缀和` | 简单 | 第 44 场双周赛 | -| 1733 | [需要教语言的最少人数](/solution/1700-1799/1733.Minimum%20Number%20of%20People%20to%20Teach/README.md) | `贪心`,`数组` | 中等 | 第 44 场双周赛 | +| 1733 | [需要教语言的最少人数](/solution/1700-1799/1733.Minimum%20Number%20of%20People%20to%20Teach/README.md) | `贪心`,`数组`,`哈希表` | 中等 | 第 44 场双周赛 | | 1734 | [解码异或后的排列](/solution/1700-1799/1734.Decode%20XORed%20Permutation/README.md) | `位运算`,`数组` | 中等 | 第 44 场双周赛 | | 1735 | [生成乘积数组的方案数](/solution/1700-1799/1735.Count%20Ways%20to%20Make%20Array%20With%20Product/README.md) | `数组`,`数学`,`动态规划`,`组合数学`,`数论` | 困难 | 第 44 场双周赛 | | 1736 | [替换隐藏数字得到的最晚时间](/solution/1700-1799/1736.Latest%20Time%20by%20Replacing%20Hidden%20Digits/README.md) | `贪心`,`字符串` | 简单 | 第 225 场周赛 | @@ -1870,7 +1870,7 @@ | 1857 | [有向图中最大颜色值](/solution/1800-1899/1857.Largest%20Color%20Value%20in%20a%20Directed%20Graph/README.md) | `图`,`拓扑排序`,`记忆化搜索`,`哈希表`,`动态规划`,`计数` | 困难 | 第 240 场周赛 | | 1858 | [包含所有前缀的最长单词](/solution/1800-1899/1858.Longest%20Word%20With%20All%20Prefixes/README.md) | `深度优先搜索`,`字典树` | 中等 | 🔒 | | 1859 | [将句子排序](/solution/1800-1899/1859.Sorting%20the%20Sentence/README.md) | `字符串`,`排序` | 简单 | 第 52 场双周赛 | -| 1860 | [增长的内存泄露](/solution/1800-1899/1860.Incremental%20Memory%20Leak/README.md) | `模拟` | 中等 | 第 52 场双周赛 | +| 1860 | [增长的内存泄露](/solution/1800-1899/1860.Incremental%20Memory%20Leak/README.md) | `数学`,`模拟` | 中等 | 第 52 场双周赛 | | 1861 | [旋转盒子](/solution/1800-1899/1861.Rotating%20the%20Box/README.md) | `数组`,`双指针`,`矩阵` | 中等 | 第 52 场双周赛 | | 1862 | [向下取整数对和](/solution/1800-1899/1862.Sum%20of%20Floored%20Pairs/README.md) | `数组`,`数学`,`二分查找`,`前缀和` | 困难 | 第 52 场双周赛 | | 1863 | [找出所有子集的异或总和再求和](/solution/1800-1899/1863.Sum%20of%20All%20Subset%20XOR%20Totals/README.md) | `位运算`,`数组`,`数学`,`回溯`,`组合数学` | 简单 | 第 241 场周赛 | @@ -1939,7 +1939,7 @@ | 1926 | [迷宫中离入口最近的出口](/solution/1900-1999/1926.Nearest%20Exit%20from%20Entrance%20in%20Maze/README.md) | `广度优先搜索`,`数组`,`矩阵` | 中等 | 第 56 场双周赛 | | 1927 | [求和游戏](/solution/1900-1999/1927.Sum%20Game/README.md) | `贪心`,`数学`,`博弈` | 中等 | 第 56 场双周赛 | | 1928 | [规定时间内到达终点的最小花费](/solution/1900-1999/1928.Minimum%20Cost%20to%20Reach%20Destination%20in%20Time/README.md) | `图`,`动态规划` | 困难 | 第 56 场双周赛 | -| 1929 | [数组串联](/solution/1900-1999/1929.Concatenation%20of%20Array/README.md) | `数组` | 简单 | 第 249 场周赛 | +| 1929 | [数组串联](/solution/1900-1999/1929.Concatenation%20of%20Array/README.md) | `数组`,`模拟` | 简单 | 第 249 场周赛 | | 1930 | [长度为 3 的不同回文子序列](/solution/1900-1999/1930.Unique%20Length-3%20Palindromic%20Subsequences/README.md) | `哈希表`,`字符串`,`前缀和` | 中等 | 第 249 场周赛 | | 1931 | [用三种不同颜色为网格涂色](/solution/1900-1999/1931.Painting%20a%20Grid%20With%20Three%20Different%20Colors/README.md) | `动态规划` | 困难 | 第 249 场周赛 | | 1932 | [合并多棵二叉搜索树](/solution/1900-1999/1932.Merge%20BSTs%20to%20Create%20Single%20BST/README.md) | `树`,`深度优先搜索`,`哈希表`,`二分查找`,`二叉树` | 困难 | 第 249 场周赛 | @@ -2119,7 +2119,7 @@ | 2106 | [摘水果](/solution/2100-2199/2106.Maximum%20Fruits%20Harvested%20After%20at%20Most%20K%20Steps/README.md) | `数组`,`二分查找`,`前缀和`,`滑动窗口` | 困难 | 第 271 场周赛 | | 2107 | [分享 K 个糖果后独特口味的数量](/solution/2100-2199/2107.Number%20of%20Unique%20Flavors%20After%20Sharing%20K%20Candies/README.md) | `数组`,`哈希表`,`滑动窗口` | 中等 | 🔒 | | 2108 | [找出数组中的第一个回文字符串](/solution/2100-2199/2108.Find%20First%20Palindromic%20String%20in%20the%20Array/README.md) | `数组`,`双指针`,`字符串` | 简单 | 第 272 场周赛 | -| 2109 | [向字符串添加空格](/solution/2100-2199/2109.Adding%20Spaces%20to%20a%20String/README.md) | `数组`,`字符串`,`模拟` | 中等 | 第 272 场周赛 | +| 2109 | [向字符串添加空格](/solution/2100-2199/2109.Adding%20Spaces%20to%20a%20String/README.md) | `数组`,`双指针`,`字符串`,`模拟` | 中等 | 第 272 场周赛 | | 2110 | [股票平滑下跌阶段的数目](/solution/2100-2199/2110.Number%20of%20Smooth%20Descent%20Periods%20of%20a%20Stock/README.md) | `数组`,`数学`,`动态规划` | 中等 | 第 272 场周赛 | | 2111 | [使数组 K 递增的最少操作次数](/solution/2100-2199/2111.Minimum%20Operations%20to%20Make%20the%20Array%20K-Increasing/README.md) | `数组`,`二分查找` | 困难 | 第 272 场周赛 | | 2112 | [最繁忙的机场](/solution/2100-2199/2112.The%20Airport%20With%20the%20Most%20Traffic/README.md) | `数据库` | 中等 | 🔒 | @@ -2486,7 +2486,7 @@ | 2473 | [购买苹果的最低成本](/solution/2400-2499/2473.Minimum%20Cost%20to%20Buy%20Apples/README.md) | `图`,`数组`,`最短路`,`堆(优先队列)` | 中等 | 🔒 | | 2474 | [购买量严格增加的客户](/solution/2400-2499/2474.Customers%20With%20Strictly%20Increasing%20Purchases/README.md) | `数据库` | 困难 | 🔒 | | 2475 | [数组中不等三元组的数目](/solution/2400-2499/2475.Number%20of%20Unequal%20Triplets%20in%20Array/README.md) | `数组`,`哈希表` | 简单 | 第 320 场周赛 | -| 2476 | [二叉搜索树最近节点查询](/solution/2400-2499/2476.Closest%20Nodes%20Queries%20in%20a%20Binary%20Search%20Tree/README.md) | `树`,`深度优先搜索`,`数组`,`二分查找`,`二叉树` | 中等 | 第 320 场周赛 | +| 2476 | [二叉搜索树最近节点查询](/solution/2400-2499/2476.Closest%20Nodes%20Queries%20in%20a%20Binary%20Search%20Tree/README.md) | `树`,`深度优先搜索`,`二叉搜索树`,`数组`,`二分查找`,`二叉树` | 中等 | 第 320 场周赛 | | 2477 | [到达首都的最少油耗](/solution/2400-2499/2477.Minimum%20Fuel%20Cost%20to%20Report%20to%20the%20Capital/README.md) | `树`,`深度优先搜索`,`广度优先搜索`,`图` | 中等 | 第 320 场周赛 | | 2478 | [完美分割的方案数](/solution/2400-2499/2478.Number%20of%20Beautiful%20Partitions/README.md) | `字符串`,`动态规划` | 困难 | 第 320 场周赛 | | 2479 | [两个不重叠子树的最大异或值](/solution/2400-2499/2479.Maximum%20XOR%20of%20Two%20Non-Overlapping%20Subtrees/README.md) | `树`,`深度优先搜索`,`图`,`字典树` | 困难 | 🔒 | @@ -2788,11 +2788,11 @@ | 2775 | [将 undefined 转为 null](/solution/2700-2799/2775.Undefined%20to%20Null/README.md) | | 中等 | 🔒 | | 2776 | [转换回调函数为 Promise 函数](/solution/2700-2799/2776.Convert%20Callback%20Based%20Function%20to%20Promise%20Based%20Function/README.md) | | 中等 | 🔒 | | 2777 | [日期范围生成器](/solution/2700-2799/2777.Date%20Range%20Generator/README.md) | | 中等 | 🔒 | -| 2778 | [特殊元素平方和](/solution/2700-2799/2778.Sum%20of%20Squares%20of%20Special%20Elements/README.md) | `数组`,`模拟` | 简单 | 第 354 场周赛 | +| 2778 | [特殊元素平方和](/solution/2700-2799/2778.Sum%20of%20Squares%20of%20Special%20Elements/README.md) | `数组`,`枚举` | 简单 | 第 354 场周赛 | | 2779 | [数组的最大美丽值](/solution/2700-2799/2779.Maximum%20Beauty%20of%20an%20Array%20After%20Applying%20Operation/README.md) | `数组`,`二分查找`,`排序`,`滑动窗口` | 中等 | 第 354 场周赛 | | 2780 | [合法分割的最小下标](/solution/2700-2799/2780.Minimum%20Index%20of%20a%20Valid%20Split/README.md) | `数组`,`哈希表`,`排序` | 中等 | 第 354 场周赛 | | 2781 | [最长合法子字符串的长度](/solution/2700-2799/2781.Length%20of%20the%20Longest%20Valid%20Substring/README.md) | `数组`,`哈希表`,`字符串`,`滑动窗口` | 困难 | 第 354 场周赛 | -| 2782 | [唯一类别的数量](/solution/2700-2799/2782.Number%20of%20Unique%20Categories/README.md) | `并查集`,`计数` | 中等 | 🔒 | +| 2782 | [唯一类别的数量](/solution/2700-2799/2782.Number%20of%20Unique%20Categories/README.md) | `并查集`,`计数`,`交互` | 中等 | 🔒 | | 2783 | [航班入座率和等待名单分析](/solution/2700-2799/2783.Flight%20Occupancy%20and%20Waitlist%20Analysis/README.md) | `数据库` | 中等 | 🔒 | | 2784 | [检查数组是否是好的](/solution/2700-2799/2784.Check%20if%20Array%20is%20Good/README.md) | `数组`,`哈希表`,`排序` | 简单 | 第 109 场双周赛 | | 2785 | [将字符串中的元音字母排序](/solution/2700-2799/2785.Sort%20Vowels%20in%20a%20String/README.md) | `字符串`,`排序` | 中等 | 第 109 场双周赛 | @@ -2808,17 +2808,17 @@ | 2795 | [并行执行 Promise 以获取独有的结果](/solution/2700-2799/2795.Parallel%20Execution%20of%20Promises%20for%20Individual%20Results%20Retrieval/README.md) | | 中等 | 🔒 | | 2796 | [重复字符串](/solution/2700-2799/2796.Repeat%20String/README.md) | | 简单 | 🔒 | | 2797 | [带有占位符的部分函数](/solution/2700-2799/2797.Partial%20Function%20with%20Placeholders/README.md) | | 简单 | 🔒 | -| 2798 | [满足目标工作时长的员工数目](/solution/2700-2799/2798.Number%20of%20Employees%20Who%20Met%20the%20Target/README.md) | `数组`,`枚举` | 简单 | 第 356 场周赛 | +| 2798 | [满足目标工作时长的员工数目](/solution/2700-2799/2798.Number%20of%20Employees%20Who%20Met%20the%20Target/README.md) | `数组` | 简单 | 第 356 场周赛 | | 2799 | [统计完全子数组的数目](/solution/2700-2799/2799.Count%20Complete%20Subarrays%20in%20an%20Array/README.md) | `数组`,`哈希表`,`滑动窗口` | 中等 | 第 356 场周赛 | | 2800 | [包含三个字符串的最短字符串](/solution/2800-2899/2800.Shortest%20String%20That%20Contains%20Three%20Strings/README.md) | `贪心`,`字符串`,`枚举` | 中等 | 第 356 场周赛 | | 2801 | [统计范围内的步进数字数目](/solution/2800-2899/2801.Count%20Stepping%20Numbers%20in%20Range/README.md) | `字符串`,`动态规划` | 困难 | 第 356 场周赛 | -| 2802 | [找出第 K 个幸运数字](/solution/2800-2899/2802.Find%20The%20K-th%20Lucky%20Number/README.md) | | 中等 | 🔒 | +| 2802 | [找出第 K 个幸运数字](/solution/2800-2899/2802.Find%20The%20K-th%20Lucky%20Number/README.md) | `位运算`,`数学` | 中等 | 🔒 | | 2803 | [阶乘生成器](/solution/2800-2899/2803.Factorial%20Generator/README.md) | | 简单 | 🔒 | | 2804 | [数组原型的 forEach 方法](/solution/2800-2899/2804.Array%20Prototype%20ForEach/README.md) | | 简单 | 🔒 | | 2805 | [自定义间隔](/solution/2800-2899/2805.Custom%20Interval/README.md) | | 中等 | 🔒 | | 2806 | [取整购买后的账户余额](/solution/2800-2899/2806.Account%20Balance%20After%20Rounded%20Purchase/README.md) | `数学` | 简单 | 第 110 场双周赛 | | 2807 | [在链表中插入最大公约数](/solution/2800-2899/2807.Insert%20Greatest%20Common%20Divisors%20in%20Linked%20List/README.md) | `链表`,`数学`,`数论` | 中等 | 第 110 场双周赛 | -| 2808 | [使循环数组所有元素相等的最少秒数](/solution/2800-2899/2808.Minimum%20Seconds%20to%20Equalize%20a%20Circular%20Array/README.md) | `贪心`,`数组`,`哈希表` | 中等 | 第 110 场双周赛 | +| 2808 | [使循环数组所有元素相等的最少秒数](/solution/2800-2899/2808.Minimum%20Seconds%20to%20Equalize%20a%20Circular%20Array/README.md) | `数组`,`哈希表` | 中等 | 第 110 场双周赛 | | 2809 | [使数组和小于等于 x 的最少时间](/solution/2800-2899/2809.Minimum%20Time%20to%20Make%20Array%20Sum%20At%20Most%20x/README.md) | `数组`,`动态规划`,`排序` | 困难 | 第 110 场双周赛 | | 2810 | [故障键盘](/solution/2800-2899/2810.Faulty%20Keyboard/README.md) | `字符串`,`模拟` | 简单 | 第 357 场周赛 | | 2811 | [判断是否能拆分数组](/solution/2800-2899/2811.Check%20if%20it%20is%20Possible%20to%20Split%20Array/README.md) | `贪心`,`数组`,`动态规划` | 中等 | 第 357 场周赛 | @@ -2834,16 +2834,16 @@ | 2821 | [延迟每个 Promise 对象的解析](/solution/2800-2899/2821.Delay%20the%20Resolution%20of%20Each%20Promise/README.md) | | 简单 | 🔒 | | 2822 | [对象反转](/solution/2800-2899/2822.Inversion%20of%20Object/README.md) | | 简单 | 🔒 | | 2823 | [深度对象筛选](/solution/2800-2899/2823.Deep%20Object%20Filter/README.md) | | 中等 | 🔒 | -| 2824 | [统计和小于目标的下标对数目](/solution/2800-2899/2824.Count%20Pairs%20Whose%20Sum%20is%20Less%20than%20Target/README.md) | `数组`,`双指针`,`排序` | 简单 | 第 111 场双周赛 | +| 2824 | [统计和小于目标的下标对数目](/solution/2800-2899/2824.Count%20Pairs%20Whose%20Sum%20is%20Less%20than%20Target/README.md) | `数组`,`双指针`,`二分查找`,`排序` | 简单 | 第 111 场双周赛 | | 2825 | [循环增长使字符串子序列等于另一个字符串](/solution/2800-2899/2825.Make%20String%20a%20Subsequence%20Using%20Cyclic%20Increments/README.md) | `双指针`,`字符串` | 中等 | 第 111 场双周赛 | -| 2826 | [将三个组排序](/solution/2800-2899/2826.Sorting%20Three%20Groups/README.md) | `数组`,`动态规划` | 中等 | 第 111 场双周赛 | +| 2826 | [将三个组排序](/solution/2800-2899/2826.Sorting%20Three%20Groups/README.md) | `数组`,`二分查找`,`动态规划` | 中等 | 第 111 场双周赛 | | 2827 | [范围中美丽整数的数目](/solution/2800-2899/2827.Number%20of%20Beautiful%20Integers%20in%20the%20Range/README.md) | `数学`,`动态规划` | 困难 | 第 111 场双周赛 | | 2828 | [判别首字母缩略词](/solution/2800-2899/2828.Check%20if%20a%20String%20Is%20an%20Acronym%20of%20Words/README.md) | `数组`,`字符串` | 简单 | 第 359 场周赛 | | 2829 | [k-avoiding 数组的最小总和](/solution/2800-2899/2829.Determine%20the%20Minimum%20Sum%20of%20a%20k-avoiding%20Array/README.md) | `贪心`,`数学` | 中等 | 第 359 场周赛 | | 2830 | [销售利润最大化](/solution/2800-2899/2830.Maximize%20the%20Profit%20as%20the%20Salesman/README.md) | `数组`,`二分查找`,`动态规划`,`排序` | 中等 | 第 359 场周赛 | | 2831 | [找出最长等值子数组](/solution/2800-2899/2831.Find%20the%20Longest%20Equal%20Subarray/README.md) | `数组`,`哈希表`,`二分查找`,`滑动窗口` | 中等 | 第 359 场周赛 | | 2832 | [每个元素为最大值的最大范围](/solution/2800-2899/2832.Maximal%20Range%20That%20Each%20Element%20Is%20Maximum%20in%20It/README.md) | `栈`,`数组`,`单调栈` | 中等 | 🔒 | -| 2833 | [距离原点最远的点](/solution/2800-2899/2833.Furthest%20Point%20From%20Origin/README.md) | `数组`,`计数` | 简单 | 第 360 场周赛 | +| 2833 | [距离原点最远的点](/solution/2800-2899/2833.Furthest%20Point%20From%20Origin/README.md) | `字符串`,`计数` | 简单 | 第 360 场周赛 | | 2834 | [找出美丽数组的最小和](/solution/2800-2899/2834.Find%20the%20Minimum%20Possible%20Sum%20of%20a%20Beautiful%20Array/README.md) | `贪心`,`数学` | 中等 | 第 360 场周赛 | | 2835 | [使子序列的和等于目标的最少操作次数](/solution/2800-2899/2835.Minimum%20Operations%20to%20Form%20Subsequence%20With%20Target%20Sum/README.md) | `贪心`,`位运算`,`数组` | 困难 | 第 360 场周赛 | | 2836 | [在传球游戏中最大化函数值](/solution/2800-2899/2836.Maximize%20Value%20of%20Function%20in%20a%20Ball%20Passing%20Game/README.md) | `位运算`,`数组`,`动态规划` | 困难 | 第 360 场周赛 | @@ -2879,7 +2879,7 @@ | 2866 | [美丽塔 II](/solution/2800-2899/2866.Beautiful%20Towers%20II/README.md) | `栈`,`数组`,`单调栈` | 中等 | 第 364 场周赛 | | 2867 | [统计树中的合法路径数目](/solution/2800-2899/2867.Count%20Valid%20Paths%20in%20a%20Tree/README.md) | `树`,`深度优先搜索`,`数学`,`动态规划`,`数论` | 困难 | 第 364 场周赛 | | 2868 | [单词游戏](/solution/2800-2899/2868.The%20Wording%20Game/README.md) | `数组`,`数学`,`双指针`,`字符串`,`博弈` | 困难 | 🔒 | -| 2869 | [收集元素的最少操作次数](/solution/2800-2899/2869.Minimum%20Operations%20to%20Collect%20Elements/README.md) | `数组`,`哈希表` | 简单 | 第 114 场双周赛 | +| 2869 | [收集元素的最少操作次数](/solution/2800-2899/2869.Minimum%20Operations%20to%20Collect%20Elements/README.md) | `位运算`,`数组`,`哈希表` | 简单 | 第 114 场双周赛 | | 2870 | [使数组为空的最少操作次数](/solution/2800-2899/2870.Minimum%20Number%20of%20Operations%20to%20Make%20Array%20Empty/README.md) | `贪心`,`数组`,`哈希表`,`计数` | 中等 | 第 114 场双周赛 | | 2871 | [将数组分割成最多数目的子数组](/solution/2800-2899/2871.Split%20Array%20Into%20Maximum%20Number%20of%20Subarrays/README.md) | `贪心`,`位运算`,`数组` | 中等 | 第 114 场双周赛 | | 2872 | [可以被 K 整除连通块的最大数目](/solution/2800-2899/2872.Maximum%20Number%20of%20K-Divisible%20Components/README.md) | `树`,`深度优先搜索` | 困难 | 第 114 场双周赛 | @@ -2913,9 +2913,9 @@ | 2900 | [最长相邻不相等子序列 I](/solution/2900-2999/2900.Longest%20Unequal%20Adjacent%20Groups%20Subsequence%20I/README.md) | `贪心`,`数组`,`字符串`,`动态规划` | 中等 | 第 115 场双周赛 | | 2901 | [最长相邻不相等子序列 II](/solution/2900-2999/2901.Longest%20Unequal%20Adjacent%20Groups%20Subsequence%20II/README.md) | `数组`,`字符串`,`动态规划` | 中等 | 第 115 场双周赛 | | 2902 | [和带限制的子多重集合的数目](/solution/2900-2999/2902.Count%20of%20Sub-Multisets%20With%20Bounded%20Sum/README.md) | `数组`,`哈希表`,`动态规划`,`滑动窗口` | 困难 | 第 115 场双周赛 | -| 2903 | [找出满足差值条件的下标 I](/solution/2900-2999/2903.Find%20Indices%20With%20Index%20and%20Value%20Difference%20I/README.md) | `数组` | 简单 | 第 367 场周赛 | +| 2903 | [找出满足差值条件的下标 I](/solution/2900-2999/2903.Find%20Indices%20With%20Index%20and%20Value%20Difference%20I/README.md) | `数组`,`双指针` | 简单 | 第 367 场周赛 | | 2904 | [最短且字典序最小的美丽子字符串](/solution/2900-2999/2904.Shortest%20and%20Lexicographically%20Smallest%20Beautiful%20String/README.md) | `字符串`,`滑动窗口` | 中等 | 第 367 场周赛 | -| 2905 | [找出满足差值条件的下标 II](/solution/2900-2999/2905.Find%20Indices%20With%20Index%20and%20Value%20Difference%20II/README.md) | `数组` | 中等 | 第 367 场周赛 | +| 2905 | [找出满足差值条件的下标 II](/solution/2900-2999/2905.Find%20Indices%20With%20Index%20and%20Value%20Difference%20II/README.md) | `数组`,`双指针` | 中等 | 第 367 场周赛 | | 2906 | [构造乘积矩阵](/solution/2900-2999/2906.Construct%20Product%20Matrix/README.md) | `数组`,`矩阵`,`前缀和` | 中等 | 第 367 场周赛 | | 2907 | [价格递增的最大利润三元组 I](/solution/2900-2999/2907.Maximum%20Profitable%20Triplets%20With%20Increasing%20Prices%20I/README.md) | `数组`,`动态规划` | 中等 | 🔒 | | 2908 | [元素和最小的山形三元组 I](/solution/2900-2999/2908.Minimum%20Sum%20of%20Mountain%20Triplets%20I/README.md) | `数组` | 简单 | 第 368 场周赛 | @@ -2944,7 +2944,7 @@ | 2931 | [购买物品的最大开销](/solution/2900-2999/2931.Maximum%20Spending%20After%20Buying%20Items/README.md) | `贪心`,`数组`,`矩阵`,`排序`,`堆(优先队列)` | 困难 | 第 117 场双周赛 | | 2932 | [找出强数对的最大异或值 I](/solution/2900-2999/2932.Maximum%20Strong%20Pair%20XOR%20I/README.md) | `位运算`,`字典树`,`数组`,`哈希表`,`滑动窗口` | 简单 | 第 371 场周赛 | | 2933 | [高访问员工](/solution/2900-2999/2933.High-Access%20Employees/README.md) | `数组`,`哈希表`,`字符串`,`排序` | 中等 | 第 371 场周赛 | -| 2934 | [最大化数组末位元素的最少操作次数](/solution/2900-2999/2934.Minimum%20Operations%20to%20Maximize%20Last%20Elements%20in%20Arrays/README.md) | `贪心`,`数组` | 中等 | 第 371 场周赛 | +| 2934 | [最大化数组末位元素的最少操作次数](/solution/2900-2999/2934.Minimum%20Operations%20to%20Maximize%20Last%20Elements%20in%20Arrays/README.md) | `数组`,`枚举` | 中等 | 第 371 场周赛 | | 2935 | [找出强数对的最大异或值 II](/solution/2900-2999/2935.Maximum%20Strong%20Pair%20XOR%20II/README.md) | `位运算`,`字典树`,`数组`,`哈希表`,`滑动窗口` | 困难 | 第 371 场周赛 | | 2936 | [包含相等值数字块的数量](/solution/2900-2999/2936.Number%20of%20Equal%20Numbers%20Blocks/README.md) | `数组`,`二分查找`,`分治` | 中等 | 🔒 | | 2937 | [使三个字符串相等](/solution/2900-2999/2937.Make%20Three%20Strings%20Equal/README.md) | `字符串` | 简单 | 第 372 场周赛 | @@ -2954,7 +2954,7 @@ | 2941 | [子数组的最大 GCD-Sum](/solution/2900-2999/2941.Maximum%20GCD-Sum%20of%20a%20Subarray/README.md) | `数组`,`数学`,`二分查找`,`数论` | 困难 | 🔒 | | 2942 | [查找包含给定字符的单词](/solution/2900-2999/2942.Find%20Words%20Containing%20Character/README.md) | `数组`,`字符串` | 简单 | 第 118 场双周赛 | | 2943 | [最大化网格图中正方形空洞的面积](/solution/2900-2999/2943.Maximize%20Area%20of%20Square%20Hole%20in%20Grid/README.md) | `数组`,`排序` | 中等 | 第 118 场双周赛 | -| 2944 | [购买水果需要的最少金币数](/solution/2900-2999/2944.Minimum%20Number%20of%20Coins%20for%20Fruits/README.md) | `队列`,`数组`,`动态规划`,`单调队列` | 中等 | 第 118 场双周赛 | +| 2944 | [购买水果需要的最少金币数](/solution/2900-2999/2944.Minimum%20Number%20of%20Coins%20for%20Fruits/README.md) | `队列`,`数组`,`动态规划`,`单调队列`,`堆(优先队列)` | 中等 | 第 118 场双周赛 | | 2945 | [找到最大非递减数组的长度](/solution/2900-2999/2945.Find%20Maximum%20Non-decreasing%20Array%20Length/README.md) | `栈`,`队列`,`数组`,`二分查找`,`动态规划`,`单调队列`,`单调栈` | 困难 | 第 118 场双周赛 | | 2946 | [循环移位后的矩阵相似检查](/solution/2900-2999/2946.Matrix%20Similarity%20After%20Cyclic%20Shifts/README.md) | `数组`,`数学`,`矩阵`,`模拟` | 简单 | 第 373 场周赛 | | 2947 | [统计美丽子字符串 I](/solution/2900-2999/2947.Count%20Beautiful%20Substrings%20I/README.md) | `字符串`,`枚举`,`前缀和` | 中等 | 第 373 场周赛 | diff --git a/solution/README_EN.md b/solution/README_EN.md index 94da977c9aacf..446286e79191e 100644 --- a/solution/README_EN.md +++ b/solution/README_EN.md @@ -262,7 +262,7 @@ Press Control + F(or Command + F on | 0251 | [Flatten 2D Vector](/solution/0200-0299/0251.Flatten%202D%20Vector/README_EN.md) | `Design`,`Array`,`Two Pointers`,`Iterator` | Medium | 🔒 | | 0252 | [Meeting Rooms](/solution/0200-0299/0252.Meeting%20Rooms/README_EN.md) | `Array`,`Sorting` | Easy | 🔒 | | 0253 | [Meeting Rooms II](/solution/0200-0299/0253.Meeting%20Rooms%20II/README_EN.md) | `Greedy`,`Array`,`Two Pointers`,`Prefix Sum`,`Sorting`,`Heap (Priority Queue)` | Medium | 🔒 | -| 0254 | [Factor Combinations](/solution/0200-0299/0254.Factor%20Combinations/README_EN.md) | `Array`,`Backtracking` | Medium | 🔒 | +| 0254 | [Factor Combinations](/solution/0200-0299/0254.Factor%20Combinations/README_EN.md) | `Backtracking` | Medium | 🔒 | | 0255 | [Verify Preorder Sequence in Binary Search Tree](/solution/0200-0299/0255.Verify%20Preorder%20Sequence%20in%20Binary%20Search%20Tree/README_EN.md) | `Stack`,`Tree`,`Binary Search Tree`,`Recursion`,`Binary Tree`,`Monotonic Stack` | Medium | 🔒 | | 0256 | [Paint House](/solution/0200-0299/0256.Paint%20House/README_EN.md) | `Array`,`Dynamic Programming` | Medium | 🔒 | | 0257 | [Binary Tree Paths](/solution/0200-0299/0257.Binary%20Tree%20Paths/README_EN.md) | `Tree`,`Depth-First Search`,`String`,`Backtracking`,`Binary Tree` | Easy | | @@ -698,7 +698,7 @@ Press Control + F(or Command + F on | 0687 | [Longest Univalue Path](/solution/0600-0699/0687.Longest%20Univalue%20Path/README_EN.md) | `Tree`,`Depth-First Search`,`Binary Tree` | Medium | | | 0688 | [Knight Probability in Chessboard](/solution/0600-0699/0688.Knight%20Probability%20in%20Chessboard/README_EN.md) | `Dynamic Programming` | Medium | | | 0689 | [Maximum Sum of 3 Non-Overlapping Subarrays](/solution/0600-0699/0689.Maximum%20Sum%20of%203%20Non-Overlapping%20Subarrays/README_EN.md) | `Array`,`Dynamic Programming` | Hard | | -| 0690 | [Employee Importance](/solution/0600-0699/0690.Employee%20Importance/README_EN.md) | `Depth-First Search`,`Breadth-First Search`,`Hash Table` | Medium | | +| 0690 | [Employee Importance](/solution/0600-0699/0690.Employee%20Importance/README_EN.md) | `Tree`,`Depth-First Search`,`Breadth-First Search`,`Array`,`Hash Table` | Medium | | | 0691 | [Stickers to Spell Word](/solution/0600-0699/0691.Stickers%20to%20Spell%20Word/README_EN.md) | `Bit Manipulation`,`Array`,`String`,`Dynamic Programming`,`Backtracking`,`Bitmask` | Hard | | | 0692 | [Top K Frequent Words](/solution/0600-0699/0692.Top%20K%20Frequent%20Words/README_EN.md) | `Trie`,`Hash Table`,`String`,`Bucket Sort`,`Counting`,`Sorting`,`Heap (Priority Queue)` | Medium | | | 0693 | [Binary Number with Alternating Bits](/solution/0600-0699/0693.Binary%20Number%20with%20Alternating%20Bits/README_EN.md) | `Bit Manipulation` | Easy | | @@ -882,7 +882,7 @@ Press Control + F(or Command + F on | 0871 | [Minimum Number of Refueling Stops](/solution/0800-0899/0871.Minimum%20Number%20of%20Refueling%20Stops/README_EN.md) | `Greedy`,`Array`,`Dynamic Programming`,`Heap (Priority Queue)` | Hard | Weekly Contest 93 | | 0872 | [Leaf-Similar Trees](/solution/0800-0899/0872.Leaf-Similar%20Trees/README_EN.md) | `Tree`,`Depth-First Search`,`Binary Tree` | Easy | Weekly Contest 94 | | 0873 | [Length of Longest Fibonacci Subsequence](/solution/0800-0899/0873.Length%20of%20Longest%20Fibonacci%20Subsequence/README_EN.md) | `Array`,`Hash Table`,`Dynamic Programming` | Medium | Weekly Contest 94 | -| 0874 | [Walking Robot Simulation](/solution/0800-0899/0874.Walking%20Robot%20Simulation/README_EN.md) | `Array`,`Simulation` | Medium | Weekly Contest 94 | +| 0874 | [Walking Robot Simulation](/solution/0800-0899/0874.Walking%20Robot%20Simulation/README_EN.md) | `Array`,`Hash Table`,`Simulation` | Medium | Weekly Contest 94 | | 0875 | [Koko Eating Bananas](/solution/0800-0899/0875.Koko%20Eating%20Bananas/README_EN.md) | `Array`,`Binary Search` | Medium | Weekly Contest 94 | | 0876 | [Middle of the Linked List](/solution/0800-0899/0876.Middle%20of%20the%20Linked%20List/README_EN.md) | `Linked List`,`Two Pointers` | Easy | Weekly Contest 95 | | 0877 | [Stone Game](/solution/0800-0899/0877.Stone%20Game/README_EN.md) | `Array`,`Math`,`Dynamic Programming`,`Game Theory` | Medium | Weekly Contest 95 | @@ -978,7 +978,7 @@ Press Control + F(or Command + F on | 0967 | [Numbers With Same Consecutive Differences](/solution/0900-0999/0967.Numbers%20With%20Same%20Consecutive%20Differences/README_EN.md) | `Breadth-First Search`,`Backtracking` | Medium | Weekly Contest 117 | | 0968 | [Binary Tree Cameras](/solution/0900-0999/0968.Binary%20Tree%20Cameras/README_EN.md) | `Tree`,`Depth-First Search`,`Dynamic Programming`,`Binary Tree` | Hard | Weekly Contest 117 | | 0969 | [Pancake Sorting](/solution/0900-0999/0969.Pancake%20Sorting/README_EN.md) | `Greedy`,`Array`,`Two Pointers`,`Sorting` | Medium | Weekly Contest 118 | -| 0970 | [Powerful Integers](/solution/0900-0999/0970.Powerful%20Integers/README_EN.md) | `Hash Table`,`Math` | Medium | Weekly Contest 118 | +| 0970 | [Powerful Integers](/solution/0900-0999/0970.Powerful%20Integers/README_EN.md) | `Hash Table`,`Math`,`Enumeration` | Medium | Weekly Contest 118 | | 0971 | [Flip Binary Tree To Match Preorder Traversal](/solution/0900-0999/0971.Flip%20Binary%20Tree%20To%20Match%20Preorder%20Traversal/README_EN.md) | `Tree`,`Depth-First Search`,`Binary Tree` | Medium | Weekly Contest 118 | | 0972 | [Equal Rational Numbers](/solution/0900-0999/0972.Equal%20Rational%20Numbers/README_EN.md) | `Math`,`String` | Hard | Weekly Contest 118 | | 0973 | [K Closest Points to Origin](/solution/0900-0999/0973.K%20Closest%20Points%20to%20Origin/README_EN.md) | `Geometry`,`Array`,`Math`,`Divide and Conquer`,`Quickselect`,`Sorting`,`Heap (Priority Queue)` | Medium | Weekly Contest 119 | @@ -1176,7 +1176,7 @@ Press Control + F(or Command + F on | 1165 | [Single-Row Keyboard](/solution/1100-1199/1165.Single-Row%20Keyboard/README_EN.md) | `Hash Table`,`String` | Easy | Biweekly Contest 7 | | 1166 | [Design File System](/solution/1100-1199/1166.Design%20File%20System/README_EN.md) | `Design`,`Trie`,`Hash Table`,`String` | Medium | Biweekly Contest 7 | | 1167 | [Minimum Cost to Connect Sticks](/solution/1100-1199/1167.Minimum%20Cost%20to%20Connect%20Sticks/README_EN.md) | `Greedy`,`Array`,`Heap (Priority Queue)` | Medium | Biweekly Contest 7 | -| 1168 | [Optimize Water Distribution in a Village](/solution/1100-1199/1168.Optimize%20Water%20Distribution%20in%20a%20Village/README_EN.md) | `Union Find`,`Graph`,`Minimum Spanning Tree` | Hard | Biweekly Contest 7 | +| 1168 | [Optimize Water Distribution in a Village](/solution/1100-1199/1168.Optimize%20Water%20Distribution%20in%20a%20Village/README_EN.md) | `Union Find`,`Graph`,`Minimum Spanning Tree`,`Heap (Priority Queue)` | Hard | Biweekly Contest 7 | | 1169 | [Invalid Transactions](/solution/1100-1199/1169.Invalid%20Transactions/README_EN.md) | `Array`,`Hash Table`,`String`,`Sorting` | Medium | Weekly Contest 151 | | 1170 | [Compare Strings by Frequency of the Smallest Character](/solution/1100-1199/1170.Compare%20Strings%20by%20Frequency%20of%20the%20Smallest%20Character/README_EN.md) | `Array`,`Hash Table`,`String`,`Binary Search`,`Sorting` | Medium | Weekly Contest 151 | | 1171 | [Remove Zero Sum Consecutive Nodes from Linked List](/solution/1100-1199/1171.Remove%20Zero%20Sum%20Consecutive%20Nodes%20from%20Linked%20List/README_EN.md) | `Hash Table`,`Linked List` | Medium | Weekly Contest 151 | @@ -1430,7 +1430,7 @@ Press Control + F(or Command + F on | 1419 | [Minimum Number of Frogs Croaking](/solution/1400-1499/1419.Minimum%20Number%20of%20Frogs%20Croaking/README_EN.md) | `String`,`Counting` | Medium | Weekly Contest 185 | | 1420 | [Build Array Where You Can Find The Maximum Exactly K Comparisons](/solution/1400-1499/1420.Build%20Array%20Where%20You%20Can%20Find%20The%20Maximum%20Exactly%20K%20Comparisons/README_EN.md) | `Dynamic Programming`,`Prefix Sum` | Hard | Weekly Contest 185 | | 1421 | [NPV Queries](/solution/1400-1499/1421.NPV%20Queries/README_EN.md) | `Database` | Easy | 🔒 | -| 1422 | [Maximum Score After Splitting a String](/solution/1400-1499/1422.Maximum%20Score%20After%20Splitting%20a%20String/README_EN.md) | `String` | Easy | Weekly Contest 186 | +| 1422 | [Maximum Score After Splitting a String](/solution/1400-1499/1422.Maximum%20Score%20After%20Splitting%20a%20String/README_EN.md) | `String`,`Prefix Sum` | Easy | Weekly Contest 186 | | 1423 | [Maximum Points You Can Obtain from Cards](/solution/1400-1499/1423.Maximum%20Points%20You%20Can%20Obtain%20from%20Cards/README_EN.md) | `Array`,`Prefix Sum`,`Sliding Window` | Medium | Weekly Contest 186 | | 1424 | [Diagonal Traverse II](/solution/1400-1499/1424.Diagonal%20Traverse%20II/README_EN.md) | `Array`,`Sorting`,`Heap (Priority Queue)` | Medium | Weekly Contest 186 | | 1425 | [Constrained Subsequence Sum](/solution/1400-1499/1425.Constrained%20Subsequence%20Sum/README_EN.md) | `Queue`,`Array`,`Dynamic Programming`,`Sliding Window`,`Monotonic Queue`,`Heap (Priority Queue)` | Hard | Weekly Contest 186 | @@ -1463,7 +1463,7 @@ Press Control + F(or Command + F on | 1452 | [People Whose List of Favorite Companies Is Not a Subset of Another List](/solution/1400-1499/1452.People%20Whose%20List%20of%20Favorite%20Companies%20Is%20Not%20a%20Subset%20of%20Another%20List/README_EN.md) | `Array`,`Hash Table`,`String` | Medium | Weekly Contest 189 | | 1453 | [Maximum Number of Darts Inside of a Circular Dartboard](/solution/1400-1499/1453.Maximum%20Number%20of%20Darts%20Inside%20of%20a%20Circular%20Dartboard/README_EN.md) | `Geometry`,`Array`,`Math` | Hard | Weekly Contest 189 | | 1454 | [Active Users](/solution/1400-1499/1454.Active%20Users/README_EN.md) | `Database` | Medium | 🔒 | -| 1455 | [Check If a Word Occurs As a Prefix of Any Word in a Sentence](/solution/1400-1499/1455.Check%20If%20a%20Word%20Occurs%20As%20a%20Prefix%20of%20Any%20Word%20in%20a%20Sentence/README_EN.md) | `String`,`String Matching` | Easy | Weekly Contest 190 | +| 1455 | [Check If a Word Occurs As a Prefix of Any Word in a Sentence](/solution/1400-1499/1455.Check%20If%20a%20Word%20Occurs%20As%20a%20Prefix%20of%20Any%20Word%20in%20a%20Sentence/README_EN.md) | `Two Pointers`,`String`,`String Matching` | Easy | Weekly Contest 190 | | 1456 | [Maximum Number of Vowels in a Substring of Given Length](/solution/1400-1499/1456.Maximum%20Number%20of%20Vowels%20in%20a%20Substring%20of%20Given%20Length/README_EN.md) | `String`,`Sliding Window` | Medium | Weekly Contest 190 | | 1457 | [Pseudo-Palindromic Paths in a Binary Tree](/solution/1400-1499/1457.Pseudo-Palindromic%20Paths%20in%20a%20Binary%20Tree/README_EN.md) | `Bit Manipulation`,`Tree`,`Depth-First Search`,`Breadth-First Search`,`Binary Tree` | Medium | Weekly Contest 190 | | 1458 | [Max Dot Product of Two Subsequences](/solution/1400-1499/1458.Max%20Dot%20Product%20of%20Two%20Subsequences/README_EN.md) | `Array`,`Dynamic Programming` | Hard | Weekly Contest 190 | @@ -1629,7 +1629,7 @@ Press Control + F(or Command + F on | 1618 | [Maximum Font to Fit a Sentence in a Screen](/solution/1600-1699/1618.Maximum%20Font%20to%20Fit%20a%20Sentence%20in%20a%20Screen/README_EN.md) | `Array`,`String`,`Binary Search`,`Interactive` | Medium | 🔒 | | 1619 | [Mean of Array After Removing Some Elements](/solution/1600-1699/1619.Mean%20of%20Array%20After%20Removing%20Some%20Elements/README_EN.md) | `Array`,`Sorting` | Easy | Biweekly Contest 37 | | 1620 | [Coordinate With Maximum Network Quality](/solution/1600-1699/1620.Coordinate%20With%20Maximum%20Network%20Quality/README_EN.md) | `Array`,`Enumeration` | Medium | Biweekly Contest 37 | -| 1621 | [Number of Sets of K Non-Overlapping Line Segments](/solution/1600-1699/1621.Number%20of%20Sets%20of%20K%20Non-Overlapping%20Line%20Segments/README_EN.md) | `Math`,`Dynamic Programming` | Medium | Biweekly Contest 37 | +| 1621 | [Number of Sets of K Non-Overlapping Line Segments](/solution/1600-1699/1621.Number%20of%20Sets%20of%20K%20Non-Overlapping%20Line%20Segments/README_EN.md) | `Math`,`Dynamic Programming`,`Combinatorics` | Medium | Biweekly Contest 37 | | 1622 | [Fancy Sequence](/solution/1600-1699/1622.Fancy%20Sequence/README_EN.md) | `Design`,`Segment Tree`,`Math` | Hard | Biweekly Contest 37 | | 1623 | [All Valid Triplets That Can Represent a Country](/solution/1600-1699/1623.All%20Valid%20Triplets%20That%20Can%20Represent%20a%20Country/README_EN.md) | `Database` | Easy | 🔒 | | 1624 | [Largest Substring Between Two Equal Characters](/solution/1600-1699/1624.Largest%20Substring%20Between%20Two%20Equal%20Characters/README_EN.md) | `Hash Table`,`String` | Easy | Weekly Contest 211 | @@ -1638,14 +1638,14 @@ Press Control + F(or Command + F on | 1627 | [Graph Connectivity With Threshold](/solution/1600-1699/1627.Graph%20Connectivity%20With%20Threshold/README_EN.md) | `Union Find`,`Array`,`Math`,`Number Theory` | Hard | Weekly Contest 211 | | 1628 | [Design an Expression Tree With Evaluate Function](/solution/1600-1699/1628.Design%20an%20Expression%20Tree%20With%20Evaluate%20Function/README_EN.md) | `Stack`,`Tree`,`Design`,`Math`,`Binary Tree` | Medium | 🔒 | | 1629 | [Slowest Key](/solution/1600-1699/1629.Slowest%20Key/README_EN.md) | `Array`,`String` | Easy | Weekly Contest 212 | -| 1630 | [Arithmetic Subarrays](/solution/1600-1699/1630.Arithmetic%20Subarrays/README_EN.md) | `Array`,`Sorting` | Medium | Weekly Contest 212 | +| 1630 | [Arithmetic Subarrays](/solution/1600-1699/1630.Arithmetic%20Subarrays/README_EN.md) | `Array`,`Hash Table`,`Sorting` | Medium | Weekly Contest 212 | | 1631 | [Path With Minimum Effort](/solution/1600-1699/1631.Path%20With%20Minimum%20Effort/README_EN.md) | `Depth-First Search`,`Breadth-First Search`,`Union Find`,`Array`,`Binary Search`,`Matrix`,`Heap (Priority Queue)` | Medium | Weekly Contest 212 | | 1632 | [Rank Transform of a Matrix](/solution/1600-1699/1632.Rank%20Transform%20of%20a%20Matrix/README_EN.md) | `Union Find`,`Graph`,`Topological Sort`,`Array`,`Matrix`,`Sorting` | Hard | Weekly Contest 212 | | 1633 | [Percentage of Users Attended a Contest](/solution/1600-1699/1633.Percentage%20of%20Users%20Attended%20a%20Contest/README_EN.md) | `Database` | Easy | | | 1634 | [Add Two Polynomials Represented as Linked Lists](/solution/1600-1699/1634.Add%20Two%20Polynomials%20Represented%20as%20Linked%20Lists/README_EN.md) | `Linked List`,`Math`,`Two Pointers` | Medium | 🔒 | | 1635 | [Hopper Company Queries I](/solution/1600-1699/1635.Hopper%20Company%20Queries%20I/README_EN.md) | `Database` | Hard | 🔒 | | 1636 | [Sort Array by Increasing Frequency](/solution/1600-1699/1636.Sort%20Array%20by%20Increasing%20Frequency/README_EN.md) | `Array`,`Hash Table`,`Sorting` | Easy | Biweekly Contest 38 | -| 1637 | [Widest Vertical Area Between Two Points Containing No Points](/solution/1600-1699/1637.Widest%20Vertical%20Area%20Between%20Two%20Points%20Containing%20No%20Points/README_EN.md) | `Array`,`Sorting` | Medium | Biweekly Contest 38 | +| 1637 | [Widest Vertical Area Between Two Points Containing No Points](/solution/1600-1699/1637.Widest%20Vertical%20Area%20Between%20Two%20Points%20Containing%20No%20Points/README_EN.md) | `Array`,`Sorting` | Easy | Biweekly Contest 38 | | 1638 | [Count Substrings That Differ by One Character](/solution/1600-1699/1638.Count%20Substrings%20That%20Differ%20by%20One%20Character/README_EN.md) | `Hash Table`,`String`,`Dynamic Programming` | Medium | Biweekly Contest 38 | | 1639 | [Number of Ways to Form a Target String Given a Dictionary](/solution/1600-1699/1639.Number%20of%20Ways%20to%20Form%20a%20Target%20String%20Given%20a%20Dictionary/README_EN.md) | `Array`,`String`,`Dynamic Programming` | Hard | Biweekly Contest 38 | | 1640 | [Check Array Formation Through Concatenation](/solution/1600-1699/1640.Check%20Array%20Formation%20Through%20Concatenation/README_EN.md) | `Array`,`Hash Table` | Easy | Weekly Contest 213 | @@ -1654,13 +1654,13 @@ Press Control + F(or Command + F on | 1643 | [Kth Smallest Instructions](/solution/1600-1699/1643.Kth%20Smallest%20Instructions/README_EN.md) | `Array`,`Math`,`Dynamic Programming`,`Combinatorics` | Hard | Weekly Contest 213 | | 1644 | [Lowest Common Ancestor of a Binary Tree II](/solution/1600-1699/1644.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Tree%20II/README_EN.md) | `Tree`,`Depth-First Search`,`Binary Tree` | Medium | 🔒 | | 1645 | [Hopper Company Queries II](/solution/1600-1699/1645.Hopper%20Company%20Queries%20II/README_EN.md) | `Database` | Hard | 🔒 | -| 1646 | [Get Maximum in Generated Array](/solution/1600-1699/1646.Get%20Maximum%20in%20Generated%20Array/README_EN.md) | `Array`,`Dynamic Programming`,`Simulation` | Easy | Weekly Contest 214 | +| 1646 | [Get Maximum in Generated Array](/solution/1600-1699/1646.Get%20Maximum%20in%20Generated%20Array/README_EN.md) | `Array`,`Simulation` | Easy | Weekly Contest 214 | | 1647 | [Minimum Deletions to Make Character Frequencies Unique](/solution/1600-1699/1647.Minimum%20Deletions%20to%20Make%20Character%20Frequencies%20Unique/README_EN.md) | `Greedy`,`Hash Table`,`String`,`Sorting` | Medium | Weekly Contest 214 | | 1648 | [Sell Diminishing-Valued Colored Balls](/solution/1600-1699/1648.Sell%20Diminishing-Valued%20Colored%20Balls/README_EN.md) | `Greedy`,`Array`,`Math`,`Binary Search`,`Sorting`,`Heap (Priority Queue)` | Medium | Weekly Contest 214 | | 1649 | [Create Sorted Array through Instructions](/solution/1600-1699/1649.Create%20Sorted%20Array%20through%20Instructions/README_EN.md) | `Binary Indexed Tree`,`Segment Tree`,`Array`,`Binary Search`,`Divide and Conquer`,`Ordered Set`,`Merge Sort` | Hard | Weekly Contest 214 | | 1650 | [Lowest Common Ancestor of a Binary Tree III](/solution/1600-1699/1650.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Tree%20III/README_EN.md) | `Tree`,`Hash Table`,`Two Pointers`,`Binary Tree` | Medium | 🔒 | | 1651 | [Hopper Company Queries III](/solution/1600-1699/1651.Hopper%20Company%20Queries%20III/README_EN.md) | `Database` | Hard | 🔒 | -| 1652 | [Defuse the Bomb](/solution/1600-1699/1652.Defuse%20the%20Bomb/README_EN.md) | `Array` | Easy | Biweekly Contest 39 | +| 1652 | [Defuse the Bomb](/solution/1600-1699/1652.Defuse%20the%20Bomb/README_EN.md) | `Array`,`Sliding Window` | Easy | Biweekly Contest 39 | | 1653 | [Minimum Deletions to Make String Balanced](/solution/1600-1699/1653.Minimum%20Deletions%20to%20Make%20String%20Balanced/README_EN.md) | `Stack`,`String`,`Dynamic Programming` | Medium | Biweekly Contest 39 | | 1654 | [Minimum Jumps to Reach Home](/solution/1600-1699/1654.Minimum%20Jumps%20to%20Reach%20Home/README_EN.md) | `Breadth-First Search`,`Array`,`Dynamic Programming` | Medium | Biweekly Contest 39 | | 1655 | [Distribute Repeating Integers](/solution/1600-1699/1655.Distribute%20Repeating%20Integers/README_EN.md) | `Bit Manipulation`,`Array`,`Dynamic Programming`,`Backtracking`,`Bitmask` | Hard | Biweekly Contest 39 | @@ -1734,14 +1734,14 @@ Press Control + F(or Command + F on | 1723 | [Find Minimum Time to Finish All Jobs](/solution/1700-1799/1723.Find%20Minimum%20Time%20to%20Finish%20All%20Jobs/README_EN.md) | `Bit Manipulation`,`Array`,`Dynamic Programming`,`Backtracking`,`Bitmask` | Hard | Weekly Contest 223 | | 1724 | [Checking Existence of Edge Length Limited Paths II](/solution/1700-1799/1724.Checking%20Existence%20of%20Edge%20Length%20Limited%20Paths%20II/README_EN.md) | `Union Find`,`Graph`,`Minimum Spanning Tree` | Hard | 🔒 | | 1725 | [Number Of Rectangles That Can Form The Largest Square](/solution/1700-1799/1725.Number%20Of%20Rectangles%20That%20Can%20Form%20The%20Largest%20Square/README_EN.md) | `Array` | Easy | Weekly Contest 224 | -| 1726 | [Tuple with Same Product](/solution/1700-1799/1726.Tuple%20with%20Same%20Product/README_EN.md) | `Array`,`Hash Table` | Medium | Weekly Contest 224 | +| 1726 | [Tuple with Same Product](/solution/1700-1799/1726.Tuple%20with%20Same%20Product/README_EN.md) | `Array`,`Hash Table`,`Counting` | Medium | Weekly Contest 224 | | 1727 | [Largest Submatrix With Rearrangements](/solution/1700-1799/1727.Largest%20Submatrix%20With%20Rearrangements/README_EN.md) | `Greedy`,`Array`,`Matrix`,`Sorting` | Medium | Weekly Contest 224 | | 1728 | [Cat and Mouse II](/solution/1700-1799/1728.Cat%20and%20Mouse%20II/README_EN.md) | `Graph`,`Topological Sort`,`Memoization`,`Array`,`Math`,`Dynamic Programming`,`Game Theory`,`Matrix` | Hard | Weekly Contest 224 | | 1729 | [Find Followers Count](/solution/1700-1799/1729.Find%20Followers%20Count/README_EN.md) | `Database` | Easy | | | 1730 | [Shortest Path to Get Food](/solution/1700-1799/1730.Shortest%20Path%20to%20Get%20Food/README_EN.md) | `Breadth-First Search`,`Array`,`Matrix` | Medium | 🔒 | | 1731 | [The Number of Employees Which Report to Each Employee](/solution/1700-1799/1731.The%20Number%20of%20Employees%20Which%20Report%20to%20Each%20Employee/README_EN.md) | `Database` | Easy | | | 1732 | [Find the Highest Altitude](/solution/1700-1799/1732.Find%20the%20Highest%20Altitude/README_EN.md) | `Array`,`Prefix Sum` | Easy | Biweekly Contest 44 | -| 1733 | [Minimum Number of People to Teach](/solution/1700-1799/1733.Minimum%20Number%20of%20People%20to%20Teach/README_EN.md) | `Greedy`,`Array` | Medium | Biweekly Contest 44 | +| 1733 | [Minimum Number of People to Teach](/solution/1700-1799/1733.Minimum%20Number%20of%20People%20to%20Teach/README_EN.md) | `Greedy`,`Array`,`Hash Table` | Medium | Biweekly Contest 44 | | 1734 | [Decode XORed Permutation](/solution/1700-1799/1734.Decode%20XORed%20Permutation/README_EN.md) | `Bit Manipulation`,`Array` | Medium | Biweekly Contest 44 | | 1735 | [Count Ways to Make Array With Product](/solution/1700-1799/1735.Count%20Ways%20to%20Make%20Array%20With%20Product/README_EN.md) | `Array`,`Math`,`Dynamic Programming`,`Combinatorics`,`Number Theory` | Hard | Biweekly Contest 44 | | 1736 | [Latest Time by Replacing Hidden Digits](/solution/1700-1799/1736.Latest%20Time%20by%20Replacing%20Hidden%20Digits/README_EN.md) | `Greedy`,`String` | Easy | Weekly Contest 225 | @@ -1868,7 +1868,7 @@ Press Control + F(or Command + F on | 1857 | [Largest Color Value in a Directed Graph](/solution/1800-1899/1857.Largest%20Color%20Value%20in%20a%20Directed%20Graph/README_EN.md) | `Graph`,`Topological Sort`,`Memoization`,`Hash Table`,`Dynamic Programming`,`Counting` | Hard | Weekly Contest 240 | | 1858 | [Longest Word With All Prefixes](/solution/1800-1899/1858.Longest%20Word%20With%20All%20Prefixes/README_EN.md) | `Depth-First Search`,`Trie` | Medium | 🔒 | | 1859 | [Sorting the Sentence](/solution/1800-1899/1859.Sorting%20the%20Sentence/README_EN.md) | `String`,`Sorting` | Easy | Biweekly Contest 52 | -| 1860 | [Incremental Memory Leak](/solution/1800-1899/1860.Incremental%20Memory%20Leak/README_EN.md) | `Simulation` | Medium | Biweekly Contest 52 | +| 1860 | [Incremental Memory Leak](/solution/1800-1899/1860.Incremental%20Memory%20Leak/README_EN.md) | `Math`,`Simulation` | Medium | Biweekly Contest 52 | | 1861 | [Rotating the Box](/solution/1800-1899/1861.Rotating%20the%20Box/README_EN.md) | `Array`,`Two Pointers`,`Matrix` | Medium | Biweekly Contest 52 | | 1862 | [Sum of Floored Pairs](/solution/1800-1899/1862.Sum%20of%20Floored%20Pairs/README_EN.md) | `Array`,`Math`,`Binary Search`,`Prefix Sum` | Hard | Biweekly Contest 52 | | 1863 | [Sum of All Subset XOR Totals](/solution/1800-1899/1863.Sum%20of%20All%20Subset%20XOR%20Totals/README_EN.md) | `Bit Manipulation`,`Array`,`Math`,`Backtracking`,`Combinatorics` | Easy | Weekly Contest 241 | @@ -1937,7 +1937,7 @@ Press Control + F(or Command + F on | 1926 | [Nearest Exit from Entrance in Maze](/solution/1900-1999/1926.Nearest%20Exit%20from%20Entrance%20in%20Maze/README_EN.md) | `Breadth-First Search`,`Array`,`Matrix` | Medium | Biweekly Contest 56 | | 1927 | [Sum Game](/solution/1900-1999/1927.Sum%20Game/README_EN.md) | `Greedy`,`Math`,`Game Theory` | Medium | Biweekly Contest 56 | | 1928 | [Minimum Cost to Reach Destination in Time](/solution/1900-1999/1928.Minimum%20Cost%20to%20Reach%20Destination%20in%20Time/README_EN.md) | `Graph`,`Dynamic Programming` | Hard | Biweekly Contest 56 | -| 1929 | [Concatenation of Array](/solution/1900-1999/1929.Concatenation%20of%20Array/README_EN.md) | `Array` | Easy | Weekly Contest 249 | +| 1929 | [Concatenation of Array](/solution/1900-1999/1929.Concatenation%20of%20Array/README_EN.md) | `Array`,`Simulation` | Easy | Weekly Contest 249 | | 1930 | [Unique Length-3 Palindromic Subsequences](/solution/1900-1999/1930.Unique%20Length-3%20Palindromic%20Subsequences/README_EN.md) | `Hash Table`,`String`,`Prefix Sum` | Medium | Weekly Contest 249 | | 1931 | [Painting a Grid With Three Different Colors](/solution/1900-1999/1931.Painting%20a%20Grid%20With%20Three%20Different%20Colors/README_EN.md) | `Dynamic Programming` | Hard | Weekly Contest 249 | | 1932 | [Merge BSTs to Create Single BST](/solution/1900-1999/1932.Merge%20BSTs%20to%20Create%20Single%20BST/README_EN.md) | `Tree`,`Depth-First Search`,`Hash Table`,`Binary Search`,`Binary Tree` | Hard | Weekly Contest 249 | @@ -2117,7 +2117,7 @@ Press Control + F(or Command + F on | 2106 | [Maximum Fruits Harvested After at Most K Steps](/solution/2100-2199/2106.Maximum%20Fruits%20Harvested%20After%20at%20Most%20K%20Steps/README_EN.md) | `Array`,`Binary Search`,`Prefix Sum`,`Sliding Window` | Hard | Weekly Contest 271 | | 2107 | [Number of Unique Flavors After Sharing K Candies](/solution/2100-2199/2107.Number%20of%20Unique%20Flavors%20After%20Sharing%20K%20Candies/README_EN.md) | `Array`,`Hash Table`,`Sliding Window` | Medium | 🔒 | | 2108 | [Find First Palindromic String in the Array](/solution/2100-2199/2108.Find%20First%20Palindromic%20String%20in%20the%20Array/README_EN.md) | `Array`,`Two Pointers`,`String` | Easy | Weekly Contest 272 | -| 2109 | [Adding Spaces to a String](/solution/2100-2199/2109.Adding%20Spaces%20to%20a%20String/README_EN.md) | `Array`,`String`,`Simulation` | Medium | Weekly Contest 272 | +| 2109 | [Adding Spaces to a String](/solution/2100-2199/2109.Adding%20Spaces%20to%20a%20String/README_EN.md) | `Array`,`Two Pointers`,`String`,`Simulation` | Medium | Weekly Contest 272 | | 2110 | [Number of Smooth Descent Periods of a Stock](/solution/2100-2199/2110.Number%20of%20Smooth%20Descent%20Periods%20of%20a%20Stock/README_EN.md) | `Array`,`Math`,`Dynamic Programming` | Medium | Weekly Contest 272 | | 2111 | [Minimum Operations to Make the Array K-Increasing](/solution/2100-2199/2111.Minimum%20Operations%20to%20Make%20the%20Array%20K-Increasing/README_EN.md) | `Array`,`Binary Search` | Hard | Weekly Contest 272 | | 2112 | [The Airport With the Most Traffic](/solution/2100-2199/2112.The%20Airport%20With%20the%20Most%20Traffic/README_EN.md) | `Database` | Medium | 🔒 | @@ -2484,7 +2484,7 @@ Press Control + F(or Command + F on | 2473 | [Minimum Cost to Buy Apples](/solution/2400-2499/2473.Minimum%20Cost%20to%20Buy%20Apples/README_EN.md) | `Graph`,`Array`,`Shortest Path`,`Heap (Priority Queue)` | Medium | 🔒 | | 2474 | [Customers With Strictly Increasing Purchases](/solution/2400-2499/2474.Customers%20With%20Strictly%20Increasing%20Purchases/README_EN.md) | `Database` | Hard | 🔒 | | 2475 | [Number of Unequal Triplets in Array](/solution/2400-2499/2475.Number%20of%20Unequal%20Triplets%20in%20Array/README_EN.md) | `Array`,`Hash Table` | Easy | Weekly Contest 320 | -| 2476 | [Closest Nodes Queries in a Binary Search Tree](/solution/2400-2499/2476.Closest%20Nodes%20Queries%20in%20a%20Binary%20Search%20Tree/README_EN.md) | `Tree`,`Depth-First Search`,`Array`,`Binary Search`,`Binary Tree` | Medium | Weekly Contest 320 | +| 2476 | [Closest Nodes Queries in a Binary Search Tree](/solution/2400-2499/2476.Closest%20Nodes%20Queries%20in%20a%20Binary%20Search%20Tree/README_EN.md) | `Tree`,`Depth-First Search`,`Binary Search Tree`,`Array`,`Binary Search`,`Binary Tree` | Medium | Weekly Contest 320 | | 2477 | [Minimum Fuel Cost to Report to the Capital](/solution/2400-2499/2477.Minimum%20Fuel%20Cost%20to%20Report%20to%20the%20Capital/README_EN.md) | `Tree`,`Depth-First Search`,`Breadth-First Search`,`Graph` | Medium | Weekly Contest 320 | | 2478 | [Number of Beautiful Partitions](/solution/2400-2499/2478.Number%20of%20Beautiful%20Partitions/README_EN.md) | `String`,`Dynamic Programming` | Hard | Weekly Contest 320 | | 2479 | [Maximum XOR of Two Non-Overlapping Subtrees](/solution/2400-2499/2479.Maximum%20XOR%20of%20Two%20Non-Overlapping%20Subtrees/README_EN.md) | `Tree`,`Depth-First Search`,`Graph`,`Trie` | Hard | 🔒 | @@ -2786,11 +2786,11 @@ Press Control + F(or Command + F on | 2775 | [Undefined to Null](/solution/2700-2799/2775.Undefined%20to%20Null/README_EN.md) | | Medium | 🔒 | | 2776 | [Convert Callback Based Function to Promise Based Function](/solution/2700-2799/2776.Convert%20Callback%20Based%20Function%20to%20Promise%20Based%20Function/README_EN.md) | | Medium | 🔒 | | 2777 | [Date Range Generator](/solution/2700-2799/2777.Date%20Range%20Generator/README_EN.md) | | Medium | 🔒 | -| 2778 | [Sum of Squares of Special Elements](/solution/2700-2799/2778.Sum%20of%20Squares%20of%20Special%20Elements/README_EN.md) | `Array`,`Simulation` | Easy | Weekly Contest 354 | +| 2778 | [Sum of Squares of Special Elements](/solution/2700-2799/2778.Sum%20of%20Squares%20of%20Special%20Elements/README_EN.md) | `Array`,`Enumeration` | Easy | Weekly Contest 354 | | 2779 | [Maximum Beauty of an Array After Applying Operation](/solution/2700-2799/2779.Maximum%20Beauty%20of%20an%20Array%20After%20Applying%20Operation/README_EN.md) | `Array`,`Binary Search`,`Sorting`,`Sliding Window` | Medium | Weekly Contest 354 | | 2780 | [Minimum Index of a Valid Split](/solution/2700-2799/2780.Minimum%20Index%20of%20a%20Valid%20Split/README_EN.md) | `Array`,`Hash Table`,`Sorting` | Medium | Weekly Contest 354 | | 2781 | [Length of the Longest Valid Substring](/solution/2700-2799/2781.Length%20of%20the%20Longest%20Valid%20Substring/README_EN.md) | `Array`,`Hash Table`,`String`,`Sliding Window` | Hard | Weekly Contest 354 | -| 2782 | [Number of Unique Categories](/solution/2700-2799/2782.Number%20of%20Unique%20Categories/README_EN.md) | `Union Find`,`Counting` | Medium | 🔒 | +| 2782 | [Number of Unique Categories](/solution/2700-2799/2782.Number%20of%20Unique%20Categories/README_EN.md) | `Union Find`,`Counting`,`Interactive` | Medium | 🔒 | | 2783 | [Flight Occupancy and Waitlist Analysis](/solution/2700-2799/2783.Flight%20Occupancy%20and%20Waitlist%20Analysis/README_EN.md) | `Database` | Medium | 🔒 | | 2784 | [Check if Array is Good](/solution/2700-2799/2784.Check%20if%20Array%20is%20Good/README_EN.md) | `Array`,`Hash Table`,`Sorting` | Easy | Biweekly Contest 109 | | 2785 | [Sort Vowels in a String](/solution/2700-2799/2785.Sort%20Vowels%20in%20a%20String/README_EN.md) | `String`,`Sorting` | Medium | Biweekly Contest 109 | @@ -2806,17 +2806,17 @@ Press Control + F(or Command + F on | 2795 | [Parallel Execution of Promises for Individual Results Retrieval](/solution/2700-2799/2795.Parallel%20Execution%20of%20Promises%20for%20Individual%20Results%20Retrieval/README_EN.md) | | Medium | 🔒 | | 2796 | [Repeat String](/solution/2700-2799/2796.Repeat%20String/README_EN.md) | | Easy | 🔒 | | 2797 | [Partial Function with Placeholders](/solution/2700-2799/2797.Partial%20Function%20with%20Placeholders/README_EN.md) | | Easy | 🔒 | -| 2798 | [Number of Employees Who Met the Target](/solution/2700-2799/2798.Number%20of%20Employees%20Who%20Met%20the%20Target/README_EN.md) | `Array`,`Enumeration` | Easy | Weekly Contest 356 | +| 2798 | [Number of Employees Who Met the Target](/solution/2700-2799/2798.Number%20of%20Employees%20Who%20Met%20the%20Target/README_EN.md) | `Array` | Easy | Weekly Contest 356 | | 2799 | [Count Complete Subarrays in an Array](/solution/2700-2799/2799.Count%20Complete%20Subarrays%20in%20an%20Array/README_EN.md) | `Array`,`Hash Table`,`Sliding Window` | Medium | Weekly Contest 356 | | 2800 | [Shortest String That Contains Three Strings](/solution/2800-2899/2800.Shortest%20String%20That%20Contains%20Three%20Strings/README_EN.md) | `Greedy`,`String`,`Enumeration` | Medium | Weekly Contest 356 | | 2801 | [Count Stepping Numbers in Range](/solution/2800-2899/2801.Count%20Stepping%20Numbers%20in%20Range/README_EN.md) | `String`,`Dynamic Programming` | Hard | Weekly Contest 356 | -| 2802 | [Find The K-th Lucky Number](/solution/2800-2899/2802.Find%20The%20K-th%20Lucky%20Number/README_EN.md) | | Medium | 🔒 | +| 2802 | [Find The K-th Lucky Number](/solution/2800-2899/2802.Find%20The%20K-th%20Lucky%20Number/README_EN.md) | `Bit Manipulation`,`Math` | Medium | 🔒 | | 2803 | [Factorial Generator](/solution/2800-2899/2803.Factorial%20Generator/README_EN.md) | | Easy | 🔒 | | 2804 | [Array Prototype ForEach](/solution/2800-2899/2804.Array%20Prototype%20ForEach/README_EN.md) | | Easy | 🔒 | | 2805 | [Custom Interval](/solution/2800-2899/2805.Custom%20Interval/README_EN.md) | | Medium | 🔒 | | 2806 | [Account Balance After Rounded Purchase](/solution/2800-2899/2806.Account%20Balance%20After%20Rounded%20Purchase/README_EN.md) | `Math` | Easy | Biweekly Contest 110 | | 2807 | [Insert Greatest Common Divisors in Linked List](/solution/2800-2899/2807.Insert%20Greatest%20Common%20Divisors%20in%20Linked%20List/README_EN.md) | `Linked List`,`Math`,`Number Theory` | Medium | Biweekly Contest 110 | -| 2808 | [Minimum Seconds to Equalize a Circular Array](/solution/2800-2899/2808.Minimum%20Seconds%20to%20Equalize%20a%20Circular%20Array/README_EN.md) | `Greedy`,`Array`,`Hash Table` | Medium | Biweekly Contest 110 | +| 2808 | [Minimum Seconds to Equalize a Circular Array](/solution/2800-2899/2808.Minimum%20Seconds%20to%20Equalize%20a%20Circular%20Array/README_EN.md) | `Array`,`Hash Table` | Medium | Biweekly Contest 110 | | 2809 | [Minimum Time to Make Array Sum At Most x](/solution/2800-2899/2809.Minimum%20Time%20to%20Make%20Array%20Sum%20At%20Most%20x/README_EN.md) | `Array`,`Dynamic Programming`,`Sorting` | Hard | Biweekly Contest 110 | | 2810 | [Faulty Keyboard](/solution/2800-2899/2810.Faulty%20Keyboard/README_EN.md) | `String`,`Simulation` | Easy | Weekly Contest 357 | | 2811 | [Check if it is Possible to Split Array](/solution/2800-2899/2811.Check%20if%20it%20is%20Possible%20to%20Split%20Array/README_EN.md) | `Greedy`,`Array`,`Dynamic Programming` | Medium | Weekly Contest 357 | @@ -2832,16 +2832,16 @@ Press Control + F(or Command + F on | 2821 | [Delay the Resolution of Each Promise](/solution/2800-2899/2821.Delay%20the%20Resolution%20of%20Each%20Promise/README_EN.md) | | Easy | 🔒 | | 2822 | [Inversion of Object](/solution/2800-2899/2822.Inversion%20of%20Object/README_EN.md) | | Easy | 🔒 | | 2823 | [Deep Object Filter](/solution/2800-2899/2823.Deep%20Object%20Filter/README_EN.md) | | Medium | 🔒 | -| 2824 | [Count Pairs Whose Sum is Less than Target](/solution/2800-2899/2824.Count%20Pairs%20Whose%20Sum%20is%20Less%20than%20Target/README_EN.md) | `Array`,`Two Pointers`,`Sorting` | Easy | Biweekly Contest 111 | +| 2824 | [Count Pairs Whose Sum is Less than Target](/solution/2800-2899/2824.Count%20Pairs%20Whose%20Sum%20is%20Less%20than%20Target/README_EN.md) | `Array`,`Two Pointers`,`Binary Search`,`Sorting` | Easy | Biweekly Contest 111 | | 2825 | [Make String a Subsequence Using Cyclic Increments](/solution/2800-2899/2825.Make%20String%20a%20Subsequence%20Using%20Cyclic%20Increments/README_EN.md) | `Two Pointers`,`String` | Medium | Biweekly Contest 111 | -| 2826 | [Sorting Three Groups](/solution/2800-2899/2826.Sorting%20Three%20Groups/README_EN.md) | `Array`,`Dynamic Programming` | Medium | Biweekly Contest 111 | +| 2826 | [Sorting Three Groups](/solution/2800-2899/2826.Sorting%20Three%20Groups/README_EN.md) | `Array`,`Binary Search`,`Dynamic Programming` | Medium | Biweekly Contest 111 | | 2827 | [Number of Beautiful Integers in the Range](/solution/2800-2899/2827.Number%20of%20Beautiful%20Integers%20in%20the%20Range/README_EN.md) | `Math`,`Dynamic Programming` | Hard | Biweekly Contest 111 | | 2828 | [Check if a String Is an Acronym of Words](/solution/2800-2899/2828.Check%20if%20a%20String%20Is%20an%20Acronym%20of%20Words/README_EN.md) | `Array`,`String` | Easy | Weekly Contest 359 | | 2829 | [Determine the Minimum Sum of a k-avoiding Array](/solution/2800-2899/2829.Determine%20the%20Minimum%20Sum%20of%20a%20k-avoiding%20Array/README_EN.md) | `Greedy`,`Math` | Medium | Weekly Contest 359 | | 2830 | [Maximize the Profit as the Salesman](/solution/2800-2899/2830.Maximize%20the%20Profit%20as%20the%20Salesman/README_EN.md) | `Array`,`Binary Search`,`Dynamic Programming`,`Sorting` | Medium | Weekly Contest 359 | | 2831 | [Find the Longest Equal Subarray](/solution/2800-2899/2831.Find%20the%20Longest%20Equal%20Subarray/README_EN.md) | `Array`,`Hash Table`,`Binary Search`,`Sliding Window` | Medium | Weekly Contest 359 | | 2832 | [Maximal Range That Each Element Is Maximum in It](/solution/2800-2899/2832.Maximal%20Range%20That%20Each%20Element%20Is%20Maximum%20in%20It/README_EN.md) | `Stack`,`Array`,`Monotonic Stack` | Medium | 🔒 | -| 2833 | [Furthest Point From Origin](/solution/2800-2899/2833.Furthest%20Point%20From%20Origin/README_EN.md) | `Array`,`Counting` | Easy | Weekly Contest 360 | +| 2833 | [Furthest Point From Origin](/solution/2800-2899/2833.Furthest%20Point%20From%20Origin/README_EN.md) | `String`,`Counting` | Easy | Weekly Contest 360 | | 2834 | [Find the Minimum Possible Sum of a Beautiful Array](/solution/2800-2899/2834.Find%20the%20Minimum%20Possible%20Sum%20of%20a%20Beautiful%20Array/README_EN.md) | `Greedy`,`Math` | Medium | Weekly Contest 360 | | 2835 | [Minimum Operations to Form Subsequence With Target Sum](/solution/2800-2899/2835.Minimum%20Operations%20to%20Form%20Subsequence%20With%20Target%20Sum/README_EN.md) | `Greedy`,`Bit Manipulation`,`Array` | Hard | Weekly Contest 360 | | 2836 | [Maximize Value of Function in a Ball Passing Game](/solution/2800-2899/2836.Maximize%20Value%20of%20Function%20in%20a%20Ball%20Passing%20Game/README_EN.md) | `Bit Manipulation`,`Array`,`Dynamic Programming` | Hard | Weekly Contest 360 | @@ -2877,7 +2877,7 @@ Press Control + F(or Command + F on | 2866 | [Beautiful Towers II](/solution/2800-2899/2866.Beautiful%20Towers%20II/README_EN.md) | `Stack`,`Array`,`Monotonic Stack` | Medium | Weekly Contest 364 | | 2867 | [Count Valid Paths in a Tree](/solution/2800-2899/2867.Count%20Valid%20Paths%20in%20a%20Tree/README_EN.md) | `Tree`,`Depth-First Search`,`Math`,`Dynamic Programming`,`Number Theory` | Hard | Weekly Contest 364 | | 2868 | [The Wording Game](/solution/2800-2899/2868.The%20Wording%20Game/README_EN.md) | `Array`,`Math`,`Two Pointers`,`String`,`Game Theory` | Hard | 🔒 | -| 2869 | [Minimum Operations to Collect Elements](/solution/2800-2899/2869.Minimum%20Operations%20to%20Collect%20Elements/README_EN.md) | `Array`,`Hash Table` | Easy | Biweekly Contest 114 | +| 2869 | [Minimum Operations to Collect Elements](/solution/2800-2899/2869.Minimum%20Operations%20to%20Collect%20Elements/README_EN.md) | `Bit Manipulation`,`Array`,`Hash Table` | Easy | Biweekly Contest 114 | | 2870 | [Minimum Number of Operations to Make Array Empty](/solution/2800-2899/2870.Minimum%20Number%20of%20Operations%20to%20Make%20Array%20Empty/README_EN.md) | `Greedy`,`Array`,`Hash Table`,`Counting` | Medium | Biweekly Contest 114 | | 2871 | [Split Array Into Maximum Number of Subarrays](/solution/2800-2899/2871.Split%20Array%20Into%20Maximum%20Number%20of%20Subarrays/README_EN.md) | `Greedy`,`Bit Manipulation`,`Array` | Medium | Biweekly Contest 114 | | 2872 | [Maximum Number of K-Divisible Components](/solution/2800-2899/2872.Maximum%20Number%20of%20K-Divisible%20Components/README_EN.md) | `Tree`,`Depth-First Search` | Hard | Biweekly Contest 114 | @@ -2911,9 +2911,9 @@ Press Control + F(or Command + F on | 2900 | [Longest Unequal Adjacent Groups Subsequence I](/solution/2900-2999/2900.Longest%20Unequal%20Adjacent%20Groups%20Subsequence%20I/README_EN.md) | `Greedy`,`Array`,`String`,`Dynamic Programming` | Medium | Biweekly Contest 115 | | 2901 | [Longest Unequal Adjacent Groups Subsequence II](/solution/2900-2999/2901.Longest%20Unequal%20Adjacent%20Groups%20Subsequence%20II/README_EN.md) | `Array`,`String`,`Dynamic Programming` | Medium | Biweekly Contest 115 | | 2902 | [Count of Sub-Multisets With Bounded Sum](/solution/2900-2999/2902.Count%20of%20Sub-Multisets%20With%20Bounded%20Sum/README_EN.md) | `Array`,`Hash Table`,`Dynamic Programming`,`Sliding Window` | Hard | Biweekly Contest 115 | -| 2903 | [Find Indices With Index and Value Difference I](/solution/2900-2999/2903.Find%20Indices%20With%20Index%20and%20Value%20Difference%20I/README_EN.md) | `Array` | Easy | Weekly Contest 367 | +| 2903 | [Find Indices With Index and Value Difference I](/solution/2900-2999/2903.Find%20Indices%20With%20Index%20and%20Value%20Difference%20I/README_EN.md) | `Array`,`Two Pointers` | Easy | Weekly Contest 367 | | 2904 | [Shortest and Lexicographically Smallest Beautiful String](/solution/2900-2999/2904.Shortest%20and%20Lexicographically%20Smallest%20Beautiful%20String/README_EN.md) | `String`,`Sliding Window` | Medium | Weekly Contest 367 | -| 2905 | [Find Indices With Index and Value Difference II](/solution/2900-2999/2905.Find%20Indices%20With%20Index%20and%20Value%20Difference%20II/README_EN.md) | `Array` | Medium | Weekly Contest 367 | +| 2905 | [Find Indices With Index and Value Difference II](/solution/2900-2999/2905.Find%20Indices%20With%20Index%20and%20Value%20Difference%20II/README_EN.md) | `Array`,`Two Pointers` | Medium | Weekly Contest 367 | | 2906 | [Construct Product Matrix](/solution/2900-2999/2906.Construct%20Product%20Matrix/README_EN.md) | `Array`,`Matrix`,`Prefix Sum` | Medium | Weekly Contest 367 | | 2907 | [Maximum Profitable Triplets With Increasing Prices I](/solution/2900-2999/2907.Maximum%20Profitable%20Triplets%20With%20Increasing%20Prices%20I/README_EN.md) | `Array`,`Dynamic Programming` | Medium | 🔒 | | 2908 | [Minimum Sum of Mountain Triplets I](/solution/2900-2999/2908.Minimum%20Sum%20of%20Mountain%20Triplets%20I/README_EN.md) | `Array` | Easy | Weekly Contest 368 | @@ -2942,7 +2942,7 @@ Press Control + F(or Command + F on | 2931 | [Maximum Spending After Buying Items](/solution/2900-2999/2931.Maximum%20Spending%20After%20Buying%20Items/README_EN.md) | `Greedy`,`Array`,`Matrix`,`Sorting`,`Heap (Priority Queue)` | Hard | Biweekly Contest 117 | | 2932 | [Maximum Strong Pair XOR I](/solution/2900-2999/2932.Maximum%20Strong%20Pair%20XOR%20I/README_EN.md) | `Bit Manipulation`,`Trie`,`Array`,`Hash Table`,`Sliding Window` | Easy | Weekly Contest 371 | | 2933 | [High-Access Employees](/solution/2900-2999/2933.High-Access%20Employees/README_EN.md) | `Array`,`Hash Table`,`String`,`Sorting` | Medium | Weekly Contest 371 | -| 2934 | [Minimum Operations to Maximize Last Elements in Arrays](/solution/2900-2999/2934.Minimum%20Operations%20to%20Maximize%20Last%20Elements%20in%20Arrays/README_EN.md) | `Greedy`,`Array` | Medium | Weekly Contest 371 | +| 2934 | [Minimum Operations to Maximize Last Elements in Arrays](/solution/2900-2999/2934.Minimum%20Operations%20to%20Maximize%20Last%20Elements%20in%20Arrays/README_EN.md) | `Array`,`Enumeration` | Medium | Weekly Contest 371 | | 2935 | [Maximum Strong Pair XOR II](/solution/2900-2999/2935.Maximum%20Strong%20Pair%20XOR%20II/README_EN.md) | `Bit Manipulation`,`Trie`,`Array`,`Hash Table`,`Sliding Window` | Hard | Weekly Contest 371 | | 2936 | [Number of Equal Numbers Blocks](/solution/2900-2999/2936.Number%20of%20Equal%20Numbers%20Blocks/README_EN.md) | `Array`,`Binary Search`,`Divide and Conquer` | Medium | 🔒 | | 2937 | [Make Three Strings Equal](/solution/2900-2999/2937.Make%20Three%20Strings%20Equal/README_EN.md) | `String` | Easy | Weekly Contest 372 | @@ -2952,7 +2952,7 @@ Press Control + F(or Command + F on | 2941 | [Maximum GCD-Sum of a Subarray](/solution/2900-2999/2941.Maximum%20GCD-Sum%20of%20a%20Subarray/README_EN.md) | `Array`,`Math`,`Binary Search`,`Number Theory` | Hard | 🔒 | | 2942 | [Find Words Containing Character](/solution/2900-2999/2942.Find%20Words%20Containing%20Character/README_EN.md) | `Array`,`String` | Easy | Biweekly Contest 118 | | 2943 | [Maximize Area of Square Hole in Grid](/solution/2900-2999/2943.Maximize%20Area%20of%20Square%20Hole%20in%20Grid/README_EN.md) | `Array`,`Sorting` | Medium | Biweekly Contest 118 | -| 2944 | [Minimum Number of Coins for Fruits](/solution/2900-2999/2944.Minimum%20Number%20of%20Coins%20for%20Fruits/README_EN.md) | `Queue`,`Array`,`Dynamic Programming`,`Monotonic Queue` | Medium | Biweekly Contest 118 | +| 2944 | [Minimum Number of Coins for Fruits](/solution/2900-2999/2944.Minimum%20Number%20of%20Coins%20for%20Fruits/README_EN.md) | `Queue`,`Array`,`Dynamic Programming`,`Monotonic Queue`,`Heap (Priority Queue)` | Medium | Biweekly Contest 118 | | 2945 | [Find Maximum Non-decreasing Array Length](/solution/2900-2999/2945.Find%20Maximum%20Non-decreasing%20Array%20Length/README_EN.md) | `Stack`,`Queue`,`Array`,`Binary Search`,`Dynamic Programming`,`Monotonic Queue`,`Monotonic Stack` | Hard | Biweekly Contest 118 | | 2946 | [Matrix Similarity After Cyclic Shifts](/solution/2900-2999/2946.Matrix%20Similarity%20After%20Cyclic%20Shifts/README_EN.md) | `Array`,`Math`,`Matrix`,`Simulation` | Easy | Weekly Contest 373 | | 2947 | [Count Beautiful Substrings I](/solution/2900-2999/2947.Count%20Beautiful%20Substrings%20I/README_EN.md) | `String`,`Enumeration`,`Prefix Sum` | Medium | Weekly Contest 373 |