mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 03:34:02 +08:00
更新 0392.判断子序列 0718.最长重复子数组 1035.不相交的线 1143.最长公共子序列 排版格式修复
This commit is contained in:
@ -28,9 +28,9 @@
|
|||||||
|
|
||||||
两个字符串都只由小写字符组成。
|
两个字符串都只由小写字符组成。
|
||||||
|
|
||||||
# 算法公开课
|
## 算法公开课
|
||||||
|
|
||||||
**《代码随想录》算法视频公开课:[动态规划,用相似思路解决复杂问题 | LeetCode:392.判断子序列](https://www.bilibili.com/video/BV1tv4y1B7ym/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。
|
**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html):[动态规划,用相似思路解决复杂问题 | LeetCode:392.判断子序列](https://www.bilibili.com/video/BV1tv4y1B7ym/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。
|
||||||
|
|
||||||
|
|
||||||
## 思路
|
## 思路
|
||||||
@ -149,8 +149,8 @@ public:
|
|||||||
|
|
||||||
## 其他语言版本
|
## 其他语言版本
|
||||||
|
|
||||||
|
### Java:
|
||||||
|
|
||||||
Java:
|
|
||||||
```java
|
```java
|
||||||
class Solution {
|
class Solution {
|
||||||
public boolean isSubsequence(String s, String t) {
|
public boolean isSubsequence(String s, String t) {
|
||||||
@ -174,7 +174,8 @@ class Solution {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Python:
|
### Python:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
class Solution:
|
class Solution:
|
||||||
def isSubsequence(self, s: str, t: str) -> bool:
|
def isSubsequence(self, s: str, t: str) -> bool:
|
||||||
@ -190,7 +191,7 @@ class Solution:
|
|||||||
return False
|
return False
|
||||||
```
|
```
|
||||||
|
|
||||||
JavaScript:
|
### JavaScript:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const isSubsequence = (s, t) => {
|
const isSubsequence = (s, t) => {
|
||||||
@ -213,7 +214,7 @@ const isSubsequence = (s, t) => {
|
|||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
TypeScript:
|
### TypeScript:
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
function isSubsequence(s: string, t: string): boolean {
|
function isSubsequence(s: string, t: string): boolean {
|
||||||
@ -237,7 +238,7 @@ function isSubsequence(s: string, t: string): boolean {
|
|||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
Go:
|
### Go:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func isSubsequence(s string, t string) bool {
|
func isSubsequence(s string, t string) bool {
|
||||||
@ -266,3 +267,4 @@ func isSubsequence(s string, t string) bool {
|
|||||||
<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>
|
||||||
|
|
||||||
|
@ -25,9 +25,7 @@
|
|||||||
|
|
||||||
## 算法公开课
|
## 算法公开课
|
||||||
|
|
||||||
**《代码随想录》算法视频公开课:[动态规划之子序列问题,想清楚DP数组的定义 | LeetCode:718.最长重复子数组](https://www.bilibili.com/video/BV178411H7hV),相信结合视频再看本篇题解,更有助于大家对本题的理解**。
|
**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html):[动态规划之子序列问题,想清楚DP数组的定义 | LeetCode:718.最长重复子数组](https://www.bilibili.com/video/BV178411H7hV),相信结合视频再看本篇题解,更有助于大家对本题的理解**。
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## 思路
|
## 思路
|
||||||
|
|
||||||
@ -126,7 +124,7 @@ public:
|
|||||||
* 时间复杂度:O(n × m),n 为A长度,m为B长度
|
* 时间复杂度:O(n × m),n 为A长度,m为B长度
|
||||||
* 空间复杂度:O(n × m)
|
* 空间复杂度:O(n × m)
|
||||||
|
|
||||||
## 滚动数组
|
### 滚动数组
|
||||||
|
|
||||||
在如下图中:
|
在如下图中:
|
||||||
|
|
||||||
@ -257,8 +255,8 @@ class Solution {
|
|||||||
|
|
||||||
## 其他语言版本
|
## 其他语言版本
|
||||||
|
|
||||||
|
### Java:
|
||||||
|
|
||||||
Java:
|
|
||||||
```java
|
```java
|
||||||
// 版本一
|
// 版本一
|
||||||
class Solution {
|
class Solution {
|
||||||
@ -300,7 +298,7 @@ class Solution {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Python:
|
### Python:
|
||||||
|
|
||||||
2维DP
|
2维DP
|
||||||
```python
|
```python
|
||||||
@ -395,7 +393,8 @@ class Solution:
|
|||||||
|
|
||||||
|
|
||||||
```
|
```
|
||||||
Go:
|
### Go:
|
||||||
|
|
||||||
```Go
|
```Go
|
||||||
func findLength(A []int, B []int) int {
|
func findLength(A []int, B []int) int {
|
||||||
m, n := len(A), len(B)
|
m, n := len(A), len(B)
|
||||||
@ -442,7 +441,7 @@ func max(a, b int) int {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
JavaScript:
|
### JavaScript:
|
||||||
|
|
||||||
> 动态规划
|
> 动态规划
|
||||||
|
|
||||||
@ -489,7 +488,7 @@ const findLength = (nums1, nums2) => {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
TypeScript:
|
### TypeScript:
|
||||||
|
|
||||||
> 动态规划:
|
> 动态规划:
|
||||||
|
|
||||||
@ -544,3 +543,4 @@ function findLength(nums1: number[], nums2: 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>
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
## 算法公开课
|
## 算法公开课
|
||||||
|
|
||||||
**《代码随想录》算法视频公开课:[动态规划之子序列问题,换汤不换药 | LeetCode:1035.不相交的线](https://www.bilibili.com/video/BV1h84y1x7MP),相信结合视频再看本篇题解,更有助于大家对本题的理解**。
|
**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html):[动态规划之子序列问题,换汤不换药 | LeetCode:1035.不相交的线](https://www.bilibili.com/video/BV1h84y1x7MP),相信结合视频再看本篇题解,更有助于大家对本题的理解**。
|
||||||
|
|
||||||
|
|
||||||
## 思路
|
## 思路
|
||||||
@ -82,8 +82,8 @@ public:
|
|||||||
|
|
||||||
## 其他语言版本
|
## 其他语言版本
|
||||||
|
|
||||||
|
### Java:
|
||||||
|
|
||||||
Java:
|
|
||||||
```java
|
```java
|
||||||
class Solution {
|
class Solution {
|
||||||
public int maxUncrossedLines(int[] nums1, int[] nums2) {
|
public int maxUncrossedLines(int[] nums1, int[] nums2) {
|
||||||
@ -106,7 +106,8 @@ Java:
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Python:
|
### Python:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
class Solution:
|
class Solution:
|
||||||
def maxUncrossedLines(self, A: List[int], B: List[int]) -> int:
|
def maxUncrossedLines(self, A: List[int], B: List[int]) -> int:
|
||||||
@ -120,8 +121,7 @@ class Solution:
|
|||||||
return dp[-1][-1]
|
return dp[-1][-1]
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Go:
|
||||||
Golang:
|
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func maxUncrossedLines(A []int, B []int) int {
|
func maxUncrossedLines(A []int, B []int) int {
|
||||||
@ -152,7 +152,7 @@ func max(a, b int) int {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Rust:
|
### Rust:
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
pub fn max_uncrossed_lines(nums1: Vec<i32>, nums2: Vec<i32>) -> i32 {
|
pub fn max_uncrossed_lines(nums1: Vec<i32>, nums2: Vec<i32>) -> i32 {
|
||||||
@ -173,7 +173,7 @@ pub fn max_uncrossed_lines(nums1: Vec<i32>, nums2: Vec<i32>) -> i32 {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
JavaScript:
|
### JavaScript:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const maxUncrossedLines = (nums1, nums2) => {
|
const maxUncrossedLines = (nums1, nums2) => {
|
||||||
@ -196,7 +196,7 @@ const maxUncrossedLines = (nums1, nums2) => {
|
|||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
TypeScript:
|
### TypeScript:
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
function maxUncrossedLines(nums1: number[], nums2: number[]): number {
|
function maxUncrossedLines(nums1: number[], nums2: number[]): number {
|
||||||
@ -224,3 +224,4 @@ function maxUncrossedLines(nums1: number[], nums2: 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>
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@
|
|||||||
|
|
||||||
## 算法公开课
|
## 算法公开课
|
||||||
|
|
||||||
**《代码随想录》算法视频公开课:[动态规划子序列问题经典题目 | LeetCode:1143.最长公共子序列](https://www.bilibili.com/video/BV1ye4y1L7CQ),相信结合视频再看本篇题解,更有助于大家对本题的理解**。
|
**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html):[动态规划子序列问题经典题目 | LeetCode:1143.最长公共子序列](https://www.bilibili.com/video/BV1ye4y1L7CQ),相信结合视频再看本篇题解,更有助于大家对本题的理解**。
|
||||||
|
|
||||||
|
|
||||||
## 思路
|
## 思路
|
||||||
@ -136,7 +136,7 @@ public:
|
|||||||
|
|
||||||
## 其他语言版本
|
## 其他语言版本
|
||||||
|
|
||||||
Java:
|
### Java:
|
||||||
|
|
||||||
```java
|
```java
|
||||||
/*
|
/*
|
||||||
@ -207,8 +207,9 @@ class Solution {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Python:
|
### Python:
|
||||||
2维DP
|
2维DP
|
||||||
|
|
||||||
```python
|
```python
|
||||||
class Solution:
|
class Solution:
|
||||||
def longestCommonSubsequence(self, text1: str, text2: str) -> int:
|
def longestCommonSubsequence(self, text1: str, text2: str) -> int:
|
||||||
@ -252,7 +253,8 @@ class Solution:
|
|||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Go:
|
### Go:
|
||||||
|
|
||||||
```Go
|
```Go
|
||||||
func longestCommonSubsequence(text1 string, text2 string) int {
|
func longestCommonSubsequence(text1 string, text2 string) int {
|
||||||
t1 := len(text1)
|
t1 := len(text1)
|
||||||
@ -283,7 +285,8 @@ func max(a,b int)int {
|
|||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Javascript:
|
### JavaScript:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const longestCommonSubsequence = (text1, text2) => {
|
const longestCommonSubsequence = (text1, text2) => {
|
||||||
let dp = Array.from(Array(text1.length+1), () => Array(text2.length+1).fill(0));
|
let dp = Array.from(Array(text1.length+1), () => Array(text2.length+1).fill(0));
|
||||||
@ -302,7 +305,7 @@ const longestCommonSubsequence = (text1, text2) => {
|
|||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
TypeScript:
|
### TypeScript:
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
function longestCommonSubsequence(text1: string, text2: string): number {
|
function longestCommonSubsequence(text1: string, text2: string): number {
|
||||||
@ -326,7 +329,8 @@ function longestCommonSubsequence(text1: string, text2: string): number {
|
|||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
Rust:
|
### Rust:
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
pub fn longest_common_subsequence(text1: String, text2: String) -> i32 {
|
pub fn longest_common_subsequence(text1: String, text2: String) -> i32 {
|
||||||
let (n, m) = (text1.len(), text2.len());
|
let (n, m) = (text1.len(), text2.len());
|
||||||
@ -353,3 +357,4 @@ pub fn longest_common_subsequence(text1: String, text2: String) -> i32 {
|
|||||||
<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