mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 19:44:45 +08:00
更新 0516.最长回文子序列 0647.回文子串 动态规划总结 排版格式修复
This commit is contained in:
@ -152,8 +152,7 @@ public:
|
|||||||
|
|
||||||
## 其他语言版本
|
## 其他语言版本
|
||||||
|
|
||||||
|
### Java:
|
||||||
Java:
|
|
||||||
|
|
||||||
```java
|
```java
|
||||||
public class Solution {
|
public class Solution {
|
||||||
@ -175,8 +174,7 @@ public class Solution {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Python:
|
||||||
Python:
|
|
||||||
|
|
||||||
```python
|
```python
|
||||||
class Solution:
|
class Solution:
|
||||||
@ -193,7 +191,7 @@ class Solution:
|
|||||||
return dp[0][-1]
|
return dp[0][-1]
|
||||||
```
|
```
|
||||||
|
|
||||||
Go:
|
### Go:
|
||||||
|
|
||||||
```Go
|
```Go
|
||||||
func longestPalindromeSubseq(s string) int {
|
func longestPalindromeSubseq(s string) int {
|
||||||
@ -222,7 +220,7 @@ func longestPalindromeSubseq(s string) int {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Javascript:
|
### Javascript:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const longestPalindromeSubseq = (s) => {
|
const longestPalindromeSubseq = (s) => {
|
||||||
@ -247,7 +245,7 @@ const longestPalindromeSubseq = (s) => {
|
|||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
TypeScript:
|
### TypeScript:
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
function longestPalindromeSubseq(s: string): number {
|
function longestPalindromeSubseq(s: string): number {
|
||||||
@ -281,3 +279,4 @@ function longestPalindromeSubseq(s: string): number {
|
|||||||
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
|
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
|
||||||
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
|
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
|
@ -26,11 +26,13 @@
|
|||||||
|
|
||||||
提示:输入的字符串长度不会超过 1000 。
|
提示:输入的字符串长度不会超过 1000 。
|
||||||
|
|
||||||
## 暴力解法
|
## 思路
|
||||||
|
|
||||||
|
### 暴力解法
|
||||||
|
|
||||||
两层for循环,遍历区间起始位置和终止位置,然后还需要一层遍历判断这个区间是不是回文。所以时间复杂度:O(n^3)
|
两层for循环,遍历区间起始位置和终止位置,然后还需要一层遍历判断这个区间是不是回文。所以时间复杂度:O(n^3)
|
||||||
|
|
||||||
## 动态规划
|
### 动态规划
|
||||||
|
|
||||||
动规五部曲:
|
动规五部曲:
|
||||||
|
|
||||||
@ -187,7 +189,7 @@ public:
|
|||||||
* 时间复杂度:O(n^2)
|
* 时间复杂度:O(n^2)
|
||||||
* 空间复杂度:O(n^2)
|
* 空间复杂度:O(n^2)
|
||||||
|
|
||||||
## 双指针法
|
### 双指针法
|
||||||
|
|
||||||
动态规划的空间复杂度是偏高的,我们再看一下双指针法。
|
动态规划的空间复杂度是偏高的,我们再看一下双指针法。
|
||||||
|
|
||||||
@ -231,7 +233,7 @@ public:
|
|||||||
|
|
||||||
## 其他语言版本
|
## 其他语言版本
|
||||||
|
|
||||||
Java:
|
### Java:
|
||||||
|
|
||||||
动态规划:
|
动态规划:
|
||||||
|
|
||||||
@ -337,7 +339,7 @@ class Solution {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Python:
|
### Python:
|
||||||
|
|
||||||
> 动态规划:
|
> 动态规划:
|
||||||
```python
|
```python
|
||||||
@ -390,7 +392,8 @@ class Solution:
|
|||||||
return res
|
return res
|
||||||
```
|
```
|
||||||
|
|
||||||
Go:
|
### Go:
|
||||||
|
|
||||||
```Go
|
```Go
|
||||||
func countSubstrings(s string) int {
|
func countSubstrings(s string) int {
|
||||||
res:=0
|
res:=0
|
||||||
@ -416,7 +419,8 @@ func countSubstrings(s string) int {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Javascript
|
### Javascript:
|
||||||
|
|
||||||
> 动态规划
|
> 动态规划
|
||||||
```javascript
|
```javascript
|
||||||
const countSubstrings = (s) => {
|
const countSubstrings = (s) => {
|
||||||
@ -462,7 +466,7 @@ const countSubstrings = (s) => {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
TypeScript:
|
### TypeScript:
|
||||||
|
|
||||||
> 动态规划:
|
> 动态规划:
|
||||||
|
|
||||||
@ -524,3 +528,4 @@ function expandRange(s: string, left: number, right: number): number {
|
|||||||
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
|
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
|
||||||
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
|
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
|
@ -136,3 +136,4 @@
|
|||||||
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
|
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
|
||||||
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
|
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user