Skip to content

chore: update lc problems #1739

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@

最后返回 `f4` 即可。

时间复杂度 $O(n)$,空间复杂度 $O(1)$。其中 $n$ 为数组 `prices` 的长度。
时间复杂度 $O(n)$,其中 $n$ 为数组 `prices` 的长度。空间复杂度 $O(1)$

<!-- tabs:start -->

Expand Down Expand Up @@ -183,8 +183,7 @@ func max(a, b int) int {
public class Solution {
public int MaxProfit(int[] prices) {
int f1 = -prices[0], f2 = 0, f3 = -prices[0], f4 = 0;
for (int i = 1; i < prices.Length; ++i)
{
for (int i = 1; i < prices.Length; ++i) {
f1 = Math.Max(f1, -prices[i]);
f2 = Math.Max(f2, f1 + prices[i]);
f3 = Math.Max(f3, f2 - prices[i]);
Expand All @@ -199,10 +198,7 @@ public class Solution {

```ts
function maxProfit(prices: number[]): number {
let f1 = -prices[0],
f2 = 0,
f3 = -prices[0],
f4 = 0;
let [f1, f2, f3, f4] = [-prices[0], 0, -prices[0], 0];
for (let i = 1; i < prices.length; ++i) {
f1 = Math.max(f1, -prices[i]);
f2 = Math.max(f2, f1 + prices[i]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,7 @@ func max(a, b int) int {
public class Solution {
public int MaxProfit(int[] prices) {
int f1 = -prices[0], f2 = 0, f3 = -prices[0], f4 = 0;
for (int i = 1; i < prices.Length; ++i)
{
for (int i = 1; i < prices.Length; ++i) {
f1 = Math.Max(f1, -prices[i]);
f2 = Math.Max(f2, f1 + prices[i]);
f3 = Math.Max(f3, f2 - prices[i]);
Expand All @@ -165,10 +164,7 @@ public class Solution {

```ts
function maxProfit(prices: number[]): number {
let f1 = -prices[0],
f2 = 0,
f3 = -prices[0],
f4 = 0;
let [f1, f2, f3, f4] = [-prices[0], 0, -prices[0], 0];
for (let i = 1; i < prices.length; ++i) {
f1 = Math.max(f1, -prices[i]);
f2 = Math.max(f2, f1 + prices[i]);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
public class Solution {
public int MaxProfit(int[] prices) {
int f1 = -prices[0], f2 = 0, f3 = -prices[0], f4 = 0;
for (int i = 1; i < prices.Length; ++i)
{
for (int i = 1; i < prices.Length; ++i) {
f1 = Math.Max(f1, -prices[i]);
f2 = Math.Max(f2, f1 + prices[i]);
f3 = Math.Max(f3, f2 - prices[i]);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
function maxProfit(prices: number[]): number {
let f1 = -prices[0],
f2 = 0,
f3 = -prices[0],
f4 = 0;
let [f1, f2, f3, f4] = [-prices[0], 0, -prices[0], 0];
for (let i = 1; i < prices.length; ++i) {
f1 = Math.max(f1, -prices[i]);
f2 = Math.max(f2, f1 + prices[i]);
Expand Down
10 changes: 7 additions & 3 deletions solution/0400-0499/0489.Robot Room Cleaner/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

<p>请利用提供的4个API编写让机器人清理整个房间的算法。</p>

<pre>interface Robot {
<pre>
interface Robot {
&nbsp; // 若下一个方格为空,则返回true,并移动至该方格
&nbsp; // 若下一个方格为障碍物,则返回false,并停留在原地
&nbsp; boolean move();
Expand All @@ -31,7 +32,10 @@

<p><strong>示例:</strong></p>

<pre><strong>输入:</strong>
<p><strong><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0400-0499/0489.Robot%20Room%20Cleaner/images/1695782910-iCEGqJ-image.png" style="width: 644px; height: 405px;" /></strong></p>

<pre>
<strong>输入:</strong>
room = [
[1,1,1,1,1,0,1,1],
[1,1,1,1,1,0,1,1],
Expand All @@ -50,7 +54,7 @@ col = 3
<p><strong>注意:</strong></p>

<ol>
<li>输入只用于初始化房间和机器人的位置。你需要&ldquo;盲解&rdquo;这个问题。换而言之,你必须在对房间和机器人位置一无所知的情况下,只使用4个给出的API解决问题。&nbsp;</li>
<li>输入只用于初始化房间和机器人的位置。你需要“盲解”这个问题。换而言之,你必须在对房间和机器人位置一无所知的情况下,只使用4个给出的API解决问题。&nbsp;</li>
<li>扫地机器人的初始位置一定是空地。</li>
<li>扫地机器人的初始方向向上。</li>
<li>所有可抵达的格子都是相连的,亦即所有标记为1的格子机器人都可以抵达。</li>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## Description

<p>Given an integer array <code>nums</code> and two integers <code>k</code> and <code>p</code>, return <em>the number of <strong>distinct subarrays,</strong> which have <strong>at most</strong></em> <code>k</code> <em>elements </em>that are&nbsp;<em>&nbsp;divisible by</em> <code>p</code>.</p>
<p>Given an integer array <code>nums</code> and two integers <code>k</code> and <code>p</code>, return <em>the number of <strong>distinct subarrays,</strong> which have <strong>at most</strong></em> <code>k</code> <em>elements </em>that are <em>divisible by</em> <code>p</code>.</p>

<p>Two arrays <code>nums1</code> and <code>nums2</code> are said to be <strong>distinct</strong> if:</p>

Expand Down
4 changes: 2 additions & 2 deletions solution/2700-2799/2782.Number of Unique Categories/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@

<p>现给定一个整数 <code>n</code> 和一个 <code>CategoryHandler</code> 类的对象 <code>categoryHandler</code> 。</p>

<p>有 <code>n</code> 个元素,编号从 <code>0</code> 到 <code>n - 1</code>。每个元素都有一个类别,你的任务是找出唯一类别的数量。</p>
<p>有 <code>n&nbsp;</code> 个元素,编号从 <code>0</code> 到 <code>n - 1</code>。每个元素都有一个类别,你的任务是找出唯一类别的数量。</p>

<p><code>CategoryHandler</code> 类包含以下方法,可能对你有帮助:</p>

<ul>
<li><code>boolean haveSameCategory(integer a, integer b)</code>:如果 <code>a</code> 和 <code>b</code> 属于相同的类别,则返回 <code>true</code>,否则返回 <code>false</code>。同时,如果 <code>a</code> 或 <code>b</code> 不是有效的数字(即大于等于 <code>n</code> 或小于 <code>0</code>),它也会返回 <code>false</code>。</li>
</ul>

<p>返回唯一类别的数量。</p>
<p>返回&nbsp;<em>唯一类别的数量</em>。</p>

<p>&nbsp;</p>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<p>You are given an integer <code>n</code> and an object <code>categoryHandler</code> of class <code>CategoryHandler</code>.</p>

<p>There are <code>n</code>elements, numbered from <code>0</code> to <code>n - 1</code>. Each element has a category, and your task is to find the number of unique categories.</p>
<p>There are <code>n&nbsp;</code>elements, numbered from <code>0</code> to <code>n - 1</code>. Each element has a category, and your task is to find the number of unique categories.</p>

<p>The class <code>CategoryHandler</code> contains the following function, which may help you:</p>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# [2872. 可以被 K 整除连通块的最大数目](https://leetcode.com/problems/maximum-number-of-k-divisible-components/)
# [2872. 可以被 K 整除连通块的最大数目](https://leetcode.cn/problems/maximum-number-of-k-divisible-components/)

[English Version](/solution/2800-2899/2872.Maximum%20Number%20of%20K-Divisible%20Components/README_EN.md)

Expand Down
6 changes: 3 additions & 3 deletions solution/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@
| 0161 | [相隔为 1 的编辑距离](/solution/0100-0199/0161.One%20Edit%20Distance/README.md) | `双指针`,`字符串` | 中等 | 🔒 |
| 0162 | [寻找峰值](/solution/0100-0199/0162.Find%20Peak%20Element/README.md) | `数组`,`二分查找` | 中等 | |
| 0163 | [缺失的区间](/solution/0100-0199/0163.Missing%20Ranges/README.md) | `数组` | 简单 | 🔒 |
| 0164 | [最大间距](/solution/0100-0199/0164.Maximum%20Gap/README.md) | `数组`,`桶排序`,`基数排序`,`排序` | 困难 | |
| 0164 | [最大间距](/solution/0100-0199/0164.Maximum%20Gap/README.md) | `数组`,`桶排序`,`基数排序`,`排序` | 中等 | |
| 0165 | [比较版本号](/solution/0100-0199/0165.Compare%20Version%20Numbers/README.md) | `双指针`,`字符串` | 中等 | |
| 0166 | [分数到小数](/solution/0100-0199/0166.Fraction%20to%20Recurring%20Decimal/README.md) | `哈希表`,`数学`,`字符串` | 中等 | |
| 0167 | [两数之和 II - 输入有序数组](/solution/0100-0199/0167.Two%20Sum%20II%20-%20Input%20Array%20Is%20Sorted/README.md) | `数组`,`双指针`,`二分查找` | 中等 | |
Expand Down Expand Up @@ -2642,7 +2642,7 @@
| 2629 | [复合函数](/solution/2600-2699/2629.Function%20Composition/README.md) | | 简单 | |
| 2630 | [记忆函数 II](/solution/2600-2699/2630.Memoize%20II/README.md) | | 困难 | |
| 2631 | [分组](/solution/2600-2699/2631.Group%20By/README.md) | | 中等 | |
| 2632 | [柯里化](/solution/2600-2699/2632.Curry/README.md) | | 中等 | 🔒 |
| 2632 | [柯里化](/solution/2600-2699/2632.Curry/README.md) | | 困难 | 🔒 |
| 2633 | [将对象转换为 JSON 字符串](/solution/2600-2699/2633.Convert%20Object%20to%20JSON%20String/README.md) | | 中等 | 🔒 |
| 2634 | [过滤数组中的元素](/solution/2600-2699/2634.Filter%20Elements%20from%20Array/README.md) | | 简单 | |
| 2635 | [转换数组中的每个元素](/solution/2600-2699/2635.Apply%20Transform%20Over%20Each%20Element%20in%20Array/README.md) | | 简单 | |
Expand Down Expand Up @@ -2807,7 +2807,7 @@
| 2794 | [从两个数组中创建对象](/solution/2700-2799/2794.Create%20Object%20from%20Two%20Arrays/README.md) | | 简单 | 🔒 |
| 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) | | 简单 | 🔒 |
| 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 场周赛 |
| 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 场周赛 |
Expand Down
6 changes: 3 additions & 3 deletions solution/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ Press <kbd>Control</kbd> + <kbd>F</kbd>(or <kbd>Command</kbd> + <kbd>F</kbd> on
| 0161 | [One Edit Distance](/solution/0100-0199/0161.One%20Edit%20Distance/README_EN.md) | `Two Pointers`,`String` | Medium | 🔒 |
| 0162 | [Find Peak Element](/solution/0100-0199/0162.Find%20Peak%20Element/README_EN.md) | `Array`,`Binary Search` | Medium | |
| 0163 | [Missing Ranges](/solution/0100-0199/0163.Missing%20Ranges/README_EN.md) | `Array` | Easy | 🔒 |
| 0164 | [Maximum Gap](/solution/0100-0199/0164.Maximum%20Gap/README_EN.md) | `Array`,`Bucket Sort`,`Radix Sort`,`Sorting` | Hard | |
| 0164 | [Maximum Gap](/solution/0100-0199/0164.Maximum%20Gap/README_EN.md) | `Array`,`Bucket Sort`,`Radix Sort`,`Sorting` | Medium | |
| 0165 | [Compare Version Numbers](/solution/0100-0199/0165.Compare%20Version%20Numbers/README_EN.md) | `Two Pointers`,`String` | Medium | |
| 0166 | [Fraction to Recurring Decimal](/solution/0100-0199/0166.Fraction%20to%20Recurring%20Decimal/README_EN.md) | `Hash Table`,`Math`,`String` | Medium | |
| 0167 | [Two Sum II - Input Array Is Sorted](/solution/0100-0199/0167.Two%20Sum%20II%20-%20Input%20Array%20Is%20Sorted/README_EN.md) | `Array`,`Two Pointers`,`Binary Search` | Medium | |
Expand Down Expand Up @@ -2640,7 +2640,7 @@ Press <kbd>Control</kbd> + <kbd>F</kbd>(or <kbd>Command</kbd> + <kbd>F</kbd> on
| 2629 | [Function Composition](/solution/2600-2699/2629.Function%20Composition/README_EN.md) | | Easy | |
| 2630 | [Memoize II](/solution/2600-2699/2630.Memoize%20II/README_EN.md) | | Hard | |
| 2631 | [Group By](/solution/2600-2699/2631.Group%20By/README_EN.md) | | Medium | |
| 2632 | [Curry](/solution/2600-2699/2632.Curry/README_EN.md) | | Medium | 🔒 |
| 2632 | [Curry](/solution/2600-2699/2632.Curry/README_EN.md) | | Hard | 🔒 |
| 2633 | [Convert Object to JSON String](/solution/2600-2699/2633.Convert%20Object%20to%20JSON%20String/README_EN.md) | | Medium | 🔒 |
| 2634 | [Filter Elements from Array](/solution/2600-2699/2634.Filter%20Elements%20from%20Array/README_EN.md) | | Easy | |
| 2635 | [Apply Transform Over Each Element in Array](/solution/2600-2699/2635.Apply%20Transform%20Over%20Each%20Element%20in%20Array/README_EN.md) | | Easy | |
Expand Down Expand Up @@ -2805,7 +2805,7 @@ Press <kbd>Control</kbd> + <kbd>F</kbd>(or <kbd>Command</kbd> + <kbd>F</kbd> on
| 2794 | [Create Object from Two Arrays](/solution/2700-2799/2794.Create%20Object%20from%20Two%20Arrays/README_EN.md) | | Easy | 🔒 |
| 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 | 🔒 |
| 2797 | [Partial Function with Placeholders](/solution/2700-2799/2797.Partial%20Function%20with%20Placeholders/README_EN.md) | | Medium | 🔒 |
| 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 |
| 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 |
Expand Down