diff --git "a/problems/0392.345円210円244円346円226円255円345円255円220円345円272円217円345円210円227円.md" "b/problems/0392.345円210円244円346円226円255円345円255円220円345円272円217円345円210円227円.md"
index 6342a41f00..12d3fa481f 100644
--- "a/problems/0392.345円210円244円346円226円255円345円255円220円345円272円217円345円210円227円.md"
+++ "b/problems/0392.345円210円244円346円226円255円345円255円220円345円272円217円345円210円227円.md"
@@ -259,9 +259,49 @@ func isSubsequence(s string, t string) bool {
}
```
+Rust:
+
+```rust
+impl Solution {
+ pub fn is_subsequence(s: String, t: String) -> bool {
+ let mut dp = vec![vec![0; t.len() + 1]; s.len() + 1];
+ for (i, char_s) in s.chars().enumerate() {
+ for (j, char_t) in t.chars().enumerate() {
+ if char_s == char_t {
+ dp[i + 1][j + 1] = dp[i][j] + 1;
+ continue;
+ }
+ dp[i + 1][j + 1] = dp[i + 1][j]
+ }
+ }
+ dp[s.len()][t.len()] == s.len()
+ }
+}
+```
-
-
+> 滚动数组
+
+```rust
+impl Solution {
+ pub fn is_subsequence(s: String, t: String) -> bool {
+ let mut dp = vec![0; t.len() + 1];
+ let (s, t) = (s.as_bytes(), t.as_bytes());
+ for &byte_s in s {
+ let mut pre = 0;
+ for j in 0..t.len() {
+ let temp = dp[j + 1];
+ if byte_s == t[j] {
+ dp[j + 1] = pre + 1;
+ } else {
+ dp[j + 1] = dp[j];
+ }
+ pre = temp;
+ }
+ }
+ dp[t.len()] == s.len()
+ }
+}
+```
diff --git "a/problems/1035.344円270円215円347円233円270円344円272円244円347円232円204円347円272円277円.md" "b/problems/1035.344円270円215円347円233円270円344円272円244円347円232円204円347円272円277円.md"
index 74e94c842f..ff9e5dc4e3 100644
--- "a/problems/1035.344円270円215円347円233円270円344円272円244円347円232円204円347円272円277円.md"
+++ "b/problems/1035.344円270円215円347円233円270円344円272円244円347円232円204円347円272円277円.md"
@@ -155,21 +155,44 @@ func max(a, b int) int {
### Rust:
```rust
-pub fn max_uncrossed_lines(nums1: Vec, nums2: Vec) -> i32 {
- let (n, m) = (nums1.len(), nums2.len());
- let mut last = vec![0; m + 1]; // 记录滚动数组
- let mut dp = vec![0; m + 1];
- for i in 1..=n {
- dp.swap_with_slice(&mut last);
- for j in 1..=m {
- if nums1[i - 1] == nums2[j - 1] {
- dp[j] = last[j - 1] + 1;
- } else {
- dp[j] = last[j].max(dp[j - 1]);
+impl Solution {
+ pub fn max_uncrossed_lines(nums1: Vec, nums2: Vec) -> i32 {
+ let mut dp = vec![vec![0; nums2.len() + 1]; nums1.len() + 1];
+ for (i, num1) in nums1.iter().enumerate() {
+ for (j, num2) in nums2.iter().enumerate() {
+ if num1 == num2 {
+ dp[i + 1][j + 1] = dp[i][j] + 1;
+ } else {
+ dp[i + 1][j + 1] = dp[i][j + 1].max(dp[i + 1][j]);
+ }
+ }
+ }
+ dp[nums1.len()][nums2.len()]
+ }
+}
+```
+
+> 滚动数组
+
+```rust
+impl Solution {
+ pub fn max_uncrossed_lines(nums1: Vec, nums2: Vec) -> i32 {
+ let mut dp = vec![0; nums2.len() + 1];
+ for num1 in nums1 {
+ let mut prev = 0;
+ for (j, &num2) in nums2.iter().enumerate() {
+ let temp = dp[j + 1];
+ if num1 == num2 {
+ // 使用上一次的状态,防止重复计算
+ dp[j + 1] = prev + 1;
+ } else {
+ dp[j + 1] = dp[j + 1].max(dp[j]);
+ }
+ prev = temp;
}
}
+ dp[nums2.len()]
}
- dp[m]
}
```
diff --git "a/problems/1143.346円234円200円351円225円277円345円205円254円345円205円261円345円255円220円345円272円217円345円210円227円.md" "b/problems/1143.346円234円200円351円225円277円345円205円254円345円205円261円345円255円220円345円272円217円345円210円227円.md"
index 260b085e14..f33391c3e6 100644
--- "a/problems/1143.346円234円200円351円225円277円345円205円254円345円205円261円345円255円220円345円272円217円345円210円227円.md"
+++ "b/problems/1143.346円234円200円351円225円277円345円205円254円345円205円261円345円255円220円345円272円217円345円210円227円.md"
@@ -329,25 +329,50 @@ function longestCommonSubsequence(text1: string, text2: string): number {
};
```
-### Rust:
+### Rust
```rust
-pub fn longest_common_subsequence(text1: String, text2: String) -> i32 {
- let (n, m) = (text1.len(), text2.len());
- let (s1, s2) = (text1.as_bytes(), text2.as_bytes());
- let mut dp = vec![0; m + 1];
- let mut last = vec![0; m + 1];
- for i in 1..=n {
- dp.swap_with_slice(&mut last);
- for j in 1..=m {
- dp[j] = if s1[i - 1] == s2[j - 1] {
- last[j - 1] + 1
- } else {
- last[j].max(dp[j - 1])
- };
+impl Solution {
+ pub fn longest_common_subsequence(text1: String, text2: String) -> i32 {
+ let mut dp = vec![vec![0; text2.len() + 1]; text1.len() + 1];
+ for (i, c1) in text1.chars().enumerate() {
+ for (j, c2) in text2.chars().enumerate() {
+ if c1 == c2 {
+ dp[i + 1][j + 1] = dp[i][j] + 1;
+ } else {
+ dp[i + 1][j + 1] = dp[i][j + 1].max(dp[i + 1][j]);
+ }
+ }
+ }
+ dp[text1.len()][text2.len()]
+ }
+}
+```
+
+一维:
+
+```rust
+impl Solution {
+ pub fn longest_common_subsequence(text1: String, text2: String) -> i32 {
+ let mut dp = vec![0; text2.len() + 1];
+ for c1 in text1.chars() {
+ // 初始化 prev
+ let mut prev = 0;
+
+ for (j, c2) in text2.chars().enumerate() {
+ let temp = dp[j + 1];
+ if c1 == c2 {
+ // 使用上一次的状态,防止重复计算
+ dp[j + 1] = prev + 1;
+ } else {
+ dp[j + 1] = dp[j + 1].max(dp[j]);
+ }
+ // 使用上一次的状态更新 prev
+ prev = temp;
+ }
}
+ dp[text2.len()]
}
- dp[m]
}
```
diff --git "a/problems/1207.347円213円254円344円270円200円346円227円240円344円272円214円347円232円204円345円207円272円347円216円260円346円254円241円346円225円260円.md" "b/problems/1207.347円213円254円344円270円200円346円227円240円344円272円214円347円232円204円345円207円272円347円216円260円346円254円241円346円225円260円.md"
index 83ebbcb7bc..2ccd30c376 100644
--- "a/problems/1207.347円213円254円344円270円200円346円227円240円344円272円214円347円232円204円345円207円272円347円216円260円346円254円241円346円225円260円.md"
+++ "b/problems/1207.347円213円254円344円270円200円346円227円240円344円272円214円347円232円204円345円207円272円347円216円260円346円254円241円346円225円260円.md"
@@ -200,10 +200,30 @@ function uniqueOccurrences(arr: number[]): boolean {
})
return countMap.size === new Set(countMap.values()).size;
};
+```
+
+
+### Go:
+```Go
+func uniqueOccurrences(arr []int) bool {
+ count := make(map[int]int) // 统计数字出现的频率
+ for _, v := range arr {
+ count[v] += 1
+ }
+ fre := make(map[int]struct{}) // 看相同频率是否重复出现
+ for _, v := range count {
+ if _, ok := fre[v]; ok {
+ return false
+ }
+ fre[v] = struct{}{}
+ }
+ return true
+}
```
+