更新 买卖股票的最佳时机系列 排版格式修复

This commit is contained in:
jinbudaily
2023-07-26 15:55:12 +08:00
parent 89571ea8f8
commit 6b322684a4
7 changed files with 63 additions and 67 deletions

View File

@ -24,11 +24,9 @@
* 输出0
解释:在这种情况下, 没有交易完成, 所以最大利润为 0。
# 算法公开课
**《代码随想录》算法视频公开课:[动态规划之 LeetCode121.买卖股票的最佳时机1](https://www.bilibili.com/video/BV1Xe4y1u77q),相信结合视频再看本篇题解,更有助于大家对本题的理解**。
## 算法公开课
**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html)[动态规划之 LeetCode121.买卖股票的最佳时机1](https://www.bilibili.com/video/BV1Xe4y1u77q),相信结合视频再看本篇题解,更有助于大家对本题的理解**。
## 思路
@ -202,7 +200,7 @@ public:
## 其他语言版本
Java:
### Java:
> 贪心法:
@ -294,8 +292,7 @@ class Solution {
```
Python:
### Python:
> 贪心法:
```python
@ -351,7 +348,8 @@ class Solution:
return dp1
```
Go:
### Go:
> 贪心法:
```Go
func maxProfit(prices []int) int {
@ -418,7 +416,7 @@ func max(a, b int) int {
}
```
JavaScript:
### JavaScript:
> 动态规划
@ -454,7 +452,7 @@ var maxProfit = function(prices) {
};
```
TypeScript
### TypeScript
> 贪心法
@ -492,7 +490,7 @@ function maxProfit(prices: number[]): number {
};
```
C#
### C#
> 贪心法
@ -533,7 +531,7 @@ public class Solution
}
```
Rust:
### Rust:
> 贪心

View File

@ -34,9 +34,9 @@
* 1 <= prices.length <= 3 * 10 ^ 4
* 0 <= prices[i] <= 10 ^ 4
# 算法公开课
## 算法公开课
**《代码随想录》算法视频公开课:[动态规划,股票问题第二弹 | LeetCode122.买卖股票的最佳时机II](https://www.bilibili.com/video/BV1D24y1Q7Ls),相信结合视频再看本篇题解,更有助于大家对本题的理解**。
**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html)[动态规划,股票问题第二弹 | LeetCode122.买卖股票的最佳时机II](https://www.bilibili.com/video/BV1D24y1Q7Ls),相信结合视频再看本篇题解,更有助于大家对本题的理解**。
## 思路
@ -133,8 +133,8 @@ public:
## 其他语言版本
### Java
Java
```java
// 动态规划
class Solution
@ -191,7 +191,7 @@ class Solution {
}
```
Python
### Python
> 版本一:
```python
@ -221,7 +221,8 @@ class Solution:
return dp[(length-1) % 2][1]
```
Go
### Go
```go
// 买卖股票的最佳时机Ⅱ 动态规划
// 时间复杂度O(n) 空间复杂度O(n)
@ -250,7 +251,8 @@ func max(a, b int) int {
}
```
Javascript
### JavaScript
```javascript
// 方法一动态规划dp 数组)
const maxProfit = (prices) => {
@ -290,7 +292,7 @@ const maxProfit = (prices) => {
}
```
TypeScript
### TypeScript
> 动态规划
@ -326,7 +328,7 @@ function maxProfit(prices: number[]): number {
};
```
C#
### C#
> 贪心法
@ -363,7 +365,7 @@ public class Solution
}
```
Rust:
### Rust:
> 贪心
@ -414,4 +416,3 @@ impl Solution {
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a>

View File

@ -39,9 +39,9 @@
* 1 <= prices.length <= 10^5
* 0 <= prices[i] <= 10^5
# 算法公开课
## 算法公开课
**《代码随想录》算法视频公开课:[动态规划,股票至多买卖两次,怎么求? | LeetCode123.买卖股票最佳时机III](https://www.bilibili.com/video/BV1WG411K7AR),相信结合视频再看本篇题解,更有助于大家对本题的理解**。
**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html)[动态规划,股票至多买卖两次,怎么求? | LeetCode123.买卖股票最佳时机III](https://www.bilibili.com/video/BV1WG411K7AR),相信结合视频再看本篇题解,更有助于大家对本题的理解**。
## 思路
@ -221,7 +221,7 @@ public:
## 其他语言版本
Java:
### Java:
```java
// 版本一
@ -277,7 +277,7 @@ class Solution {
}
```
Python:
### Python:
> 版本一:
```python
@ -314,7 +314,7 @@ class Solution:
return dp[4]
```
Go:
### Go:
```go
func maxProfit(prices []int) int {
@ -344,7 +344,7 @@ func max(a, b int) int {
}
```
JavaScript:
### JavaScript:
> 版本一:
@ -383,7 +383,7 @@ const maxProfit = prices => {
};
```
TypeScript
### TypeScript
> 版本一
@ -413,7 +413,7 @@ function maxProfit(prices: number[]): number {
};
```
Rust
### Rust
> 版本一
@ -465,3 +465,4 @@ impl Solution {
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a>

View File

@ -31,9 +31,9 @@
* 0 <= prices.length <= 1000
* 0 <= prices[i] <= 1000
# 算法公开课
## 算法公开课
**《代码随想录》算法视频公开课:[动态规划来决定最佳时机至多可以买卖K次| LeetCode188.买卖股票最佳时机4](https://www.bilibili.com/video/BV16M411U7XJ),相信结合视频再看本篇题解,更有助于大家对本题的理解**。
**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html)[动态规划来决定最佳时机至多可以买卖K次| LeetCode188.买卖股票最佳时机4](https://www.bilibili.com/video/BV16M411U7XJ),相信结合视频再看本篇题解,更有助于大家对本题的理解**。
## 思路
@ -173,7 +173,7 @@ public:
## 其他语言版本
Java:
### Java:
```java
// 版本一: 三维 dp数组
@ -295,7 +295,7 @@ class Solution {
}
```
Python:
### Python:
版本一
@ -329,7 +329,7 @@ class Solution:
dp[j] = max(dp[j],dp[j-1]+prices[i])
return dp[2*k]
```
Go:
### Go:
版本一:
@ -404,7 +404,7 @@ func max188(a, b int) int {
}
```
Javascript:
### JavaScript:
```javascript
// 方法一:动态规划
@ -454,7 +454,7 @@ var maxProfit = function(k, prices) {
};
```
TypeScript
### TypeScript
```typescript
function maxProfit(k: number, prices: number[]): number {
@ -474,7 +474,7 @@ function maxProfit(k: number, prices: number[]): number {
};
```
Rust
### Rust
```rust
impl Solution {
@ -529,3 +529,4 @@ impl Solution {
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a>

View File

@ -20,9 +20,9 @@
* 输出: 3
* 解释: 对应的交易状态为: [买入, 卖出, 冷冻期, 买入, 卖出]
# 算法公开课
## 算法公开课
**《代码随想录》算法视频公开课:[动态规划来决定最佳时机,这次有冷冻期!| LeetCode309.买卖股票的最佳时机含冷冻期](https://www.bilibili.com/video/BV1rP4y1D7ku),相信结合视频再看本篇题解,更有助于大家对本题的理解**。
**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html)[动态规划来决定最佳时机,这次有冷冻期!| LeetCode309.买卖股票的最佳时机含冷冻期](https://www.bilibili.com/video/BV1rP4y1D7ku),相信结合视频再看本篇题解,更有助于大家对本题的理解**。
## 思路
@ -174,7 +174,7 @@ public:
## 其他语言版本
Java
### Java
```java
class Solution {
@ -273,8 +273,9 @@ class Solution {
}
```
Python
### Python
版本一
```python
from typing import List
@ -319,7 +320,8 @@ class Solution:
return max(dp[-1][1], dp[-1][2])
```
Go
### Go
```go
// 最佳买卖股票时机含冷冻期 动态规划
// 时间复杂度O(n) 空间复杂度O(n)
@ -355,7 +357,7 @@ func max(a, b int) int {
}
```
Javascript:
### Javascript:
```javascript
const maxProfit = (prices) => {
@ -397,7 +399,7 @@ const maxProfit = (prices) => {
};
```
TypeScript
### TypeScript
> 版本一,与本文思路一致
@ -455,7 +457,7 @@ function maxProfit(prices: number[]): number {
};
```
Rust
### Rust
```rust
impl Solution {
@ -484,3 +486,4 @@ impl Solution {
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a>

View File

@ -32,9 +32,9 @@
* 0 < prices[i] < 50000.
* 0 <= fee < 50000.
# 算法公开课
## 算法公开课
**代码随想录算法视频公开课[动态规划来决定最佳时机,这次含手续费!| LeetCode714.买卖股票的最佳时机含手续费](https://www.bilibili.com/video/BV1z44y1Z7UR)相信结合视频再看本篇题解更有助于大家对本题的理解**。
**[代码随想录算法视频公开课](https://programmercarl.com/other/gongkaike.html)[动态规划来决定最佳时机,这次含手续费!| LeetCode714.买卖股票的最佳时机含手续费](https://www.bilibili.com/video/BV1z44y1Z7UR)相信结合视频再看本篇题解更有助于大家对本题的理解**。
## 思路
@ -97,8 +97,8 @@ public:
## 其他语言版本
### Java
Java
```java
/**
* 卖出时支付手续费
@ -173,9 +173,9 @@ class Solution {
}
}
```
```
### python
Python
```python
class Solution:
def maxProfit(self, prices: List[int], fee: int) -> int:
@ -188,7 +188,8 @@ class Solution:
return max(dp[-1][0], dp[-1][1])
```
Go
### Go
```go
// 买卖股票的最佳时机含手续费 动态规划
// 时间复杂度O(n) 空间复杂度O(n)
@ -211,7 +212,8 @@ func max(a, b int) int {
}
```
Javascript
### Javascript
```javascript
const maxProfit = (prices,fee) => {
let dp = Array.from(Array(prices.length), () => Array(2).fill(0));
@ -224,7 +226,7 @@ const maxProfit = (prices,fee) => {
}
```
TypeScript
### TypeScript
```typescript
function maxProfit(prices: number[], fee: number): number {
@ -245,8 +247,9 @@ function maxProfit(prices: number[], fee: number): number {
};
```
Rust:
### Rust:
**贪心**
```Rust
impl Solution {
pub fn max_profit(prices: Vec<i32>, fee: i32) -> i32 {

View File

@ -471,21 +471,10 @@ public:
「代码随想录」值得推荐给身边每一位学习算法的朋友同学们,关注后都会发现相见恨晚!
## 其他语言版本
Java
Python
Go
<p align="center">
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a>