diff --git "a/problems/0072.347円274円226円350円276円221円350円267円235円347円246円273円.md" "b/problems/0072.347円274円226円350円276円221円350円267円235円347円246円273円.md" index a15012d75a..df57b5b882 100644 --- "a/problems/0072.347円274円226円350円276円221円350円267円235円347円246円273円.md" +++ "b/problems/0072.347円274円226円350円276円221円350円267円235円347円246円273円.md" @@ -364,6 +364,7 @@ function minDistance(word1: string, word2: string): number { C: + ```c int min(int num1, int num2, int num3) { return num1> num2 ? (num2> num3 ? num3 : num2) : (num1> num3 ? num3 : num1); @@ -376,7 +377,7 @@ int minDistance(char * word1, char * word2){ for (int i = 1; i <= strlen(word2); i++) dp[0][i] = i; for (int i = 1; i <= strlen(word1); i++) { - for (int j = 1; j <=strlen(word2); j++) { + for (int j = 1; j <= strlen(word2); j++) { if (word1[i-1] == word2[j-1]) { dp[i][j] = dp[i-1][j-1]; } @@ -389,7 +390,5 @@ int minDistance(char * word1, char * word2){ } ``` - - -----------------------
diff --git "a/problems/0090.345円255円220円351円233円206円II.md" "b/problems/0090.345円255円220円351円233円206円II.md" index 9e7e3bd01b..81c0f94a80 100644 --- "a/problems/0090.345円255円220円351円233円206円II.md" +++ "b/problems/0090.345円255円220円351円233円206円II.md" @@ -367,6 +367,39 @@ function subsetsWithDup(nums: number[]): number[][] { }; ``` +set去重版本: +```typescript +// 使用set去重版本 +function subsetsWithDup(nums: number[]): number[][] { + const result: number[][] = []; + const path: number[] = []; + // 去重之前先排序 + nums.sort((a, b) => a - b); + function backTracking(startIndex: number) { + // 收集结果 + result.push([...path]) + // 此处不返回也可以因为,每次递归都会使startIndex + 1,当这个数大到nums.length的时候就不会进入递归了。 + if (startIndex === nums.length) { + return + } + // 定义每一个树层的set集合 + const set: Set = new Set() + for (let i = startIndex; i < nums.length; i++) { + // 去重 + if (set.has(nums[i])) { + continue + } + set.add(nums[i]) + path.push(nums[i]) + backTracking(i + 1) + // 回溯 + path.pop() + } + } + backTracking(0) + return result +}; +``` ### Rust ```Rust

AltStyle によって変換されたページ (->オリジナル) /