更新 贪心与动态规划 额外题目 排版格式修复

This commit is contained in:
jinbudaily
2023-07-27 14:41:58 +08:00
parent bbb2a60f8a
commit e9b0d46f35
4 changed files with 35 additions and 31 deletions

View File

@ -30,17 +30,17 @@
* 输出:"a"
# 思路
## 思路
本题和[647.回文子串](https://programmercarl.com/0647.回文子串.html) 差不多是一样的但647.回文子串更基本一点建议可以先做647.回文子串
## 暴力解法
### 暴力解法
两层for循环遍历区间起始位置和终止位置然后判断这个区间是不是回文。
时间复杂度O(n^3)
## 动态规划
### 动态规划
动规五部曲:
@ -208,7 +208,7 @@ public:
* 时间复杂度O(n^2)
* 空间复杂度O(n^2)
## 双指针
### 双指针
动态规划的空间复杂度是偏高的,我们再看一下双指针法。
@ -258,9 +258,9 @@ public:
# 其他语言版本
## 其他语言版本
Java
### Java
```java
// 双指针 动态规划
@ -327,7 +327,7 @@ class Solution {
}
```
Python
### Python
```python
class Solution:
@ -377,7 +377,7 @@ class Solution:
return s[start:end]
```
Go
### Go
```go
func longestPalindrome(s string) string {
@ -411,7 +411,7 @@ func longestPalindrome(s string) string {
```
JavaScript
### JavaScript
```js
//动态规划解法
@ -527,7 +527,7 @@ var longestPalindrome = function(s) {
};
```
C
### C
动态规划:
```c
@ -615,7 +615,7 @@ char * longestPalindrome(char * s){
}
```
C#
### C#
動態規則:
```c#
@ -681,3 +681,4 @@ public class Solution {
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a>

View File

@ -34,7 +34,7 @@
* 1 <= s.length <= 2000
* s 仅由小写英文字母组成
# 思路
## 思路
我们在讲解回溯法系列的时候,讲过了这道题目[回溯算法131.分割回文串](https://programmercarl.com/0131.分割回文串.html)。
@ -201,9 +201,9 @@ public:
```
# 其他语言版本
## 其他语言版本
## Java
### Java
```java
class Solution {
@ -257,7 +257,7 @@ class Solution {
}
```
## Python
### Python
```python
class Solution:
@ -286,7 +286,7 @@ class Solution:
return dp[-1]
```
## Go
### Go
```go
func minCut(s string) int {
@ -330,7 +330,7 @@ func min(i, j int) int {
}
```
## JavaScript
### JavaScript
```js
var minCut = function(s) {
@ -376,3 +376,4 @@ var minCut = function(s) {
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a>

View File

@ -42,7 +42,7 @@ Dota2 参议院由来自两派的参议员组成。现在参议院希望对一
因此在第二轮只剩下第三个参议员拥有投票的权利,于是他可以宣布胜利。
# 思路
## 思路
这道题 题意太绕了,我举一个更形象的例子给大家捋顺一下。
@ -70,7 +70,7 @@ Dota2 参议院由来自两派的参议员组成。现在参议院希望对一
如果对贪心算法理论基础还不了解的话,可以看看这篇:[关于贪心算法,你该了解这些!](https://programmercarl.com/贪心算法理论基础.html) ,相信看完之后对贪心就有基本的了解了。
# 代码实现
## 代码实现
实现代码,在每一轮循环的过程中,去过模拟优先消灭身后的对手,其实是比较麻烦的。
@ -111,9 +111,9 @@ public:
# 其他语言版本
## 其他语言版本
## Java
### Java
```java
class Solution {
@ -145,7 +145,7 @@ class Solution {
}
```
## Python
### Python
```python
class Solution:
@ -173,7 +173,7 @@ class Solution:
return "Radiant" if R else "Dire"
```
## Go
### Go
```go
@ -214,7 +214,7 @@ func predictPartyVictory(senateStr string) string {
}
```
## JavaScript
### JavaScript
```js
var predictPartyVictory = function(senateStr) {
@ -244,7 +244,7 @@ var predictPartyVictory = function(senateStr) {
};
```
## TypeScript
### TypeScript
```typescript
function predictPartyVictory(senate: string): string {
@ -287,3 +287,4 @@ function predictPartyVictory(senate: string): string {
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a>

View File

@ -24,7 +24,7 @@
* 解释: 最长递增子序列的长度是1并且存在5个子序列的长度为1因此输出5。
# 思路
## 思路
这道题可以说是 [300.最长上升子序列](https://programmercarl.com/0300.最长上升子序列.html) 的进阶版本
@ -221,9 +221,9 @@ public:
还有O(nlog n)的解法使用树状数组今天有点忙就先不写了感兴趣的同学可以自行学习一下这里有我之前写的树状数组系列博客https://blog.csdn.net/youngyangyang04/category_871105.html (十年前的陈年老文了)
# 其他语言版本
## 其他语言版本
## Java
### Java
```java
class Solution {
@ -257,7 +257,7 @@ class Solution {
}
```
## Python
### Python
```python
class Solution:
@ -286,7 +286,7 @@ class Solution:
return result;
```
## Go
### Go
```go
@ -332,7 +332,7 @@ func findNumberOfLIS(nums []int) int {
}
```
## JavaScript
### JavaScript
```js
var findNumberOfLIS = function(nums) {
@ -364,3 +364,4 @@ var findNumberOfLIS = function(nums) {
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a>