Re-translate the Japanese version (#1871)

* Retranslate Japanese docs with GPT-5.4

* Retranslate Japanese code with GPT-5.4
This commit is contained in:
Yudong Jin
2026-03-30 07:30:15 +08:00
committed by GitHub
parent fe6443235b
commit d7b2277d2b
1444 changed files with 83312 additions and 8363 deletions
@@ -0,0 +1,52 @@
/**
* File: permutations_ii.swift
* Created Time: 2023-04-30
* Author: nuomi1 (nuomi1@qq.com)
*/
/* II */
func backtrack(state: inout [Int], choices: [Int], selected: inout [Bool], res: inout [[Int]]) {
//
if state.count == choices.count {
res.append(state)
return
}
//
var duplicated: Set<Int> = []
for (i, choice) in choices.enumerated() {
//
if !selected[i], !duplicated.contains(choice) {
// :
duplicated.insert(choice) //
selected[i] = true
state.append(choice)
//
backtrack(state: &state, choices: choices, selected: &selected, res: &res)
//
selected[i] = false
state.removeLast()
}
}
}
/* II */
func permutationsII(nums: [Int]) -> [[Int]] {
var state: [Int] = []
var selected = Array(repeating: false, count: nums.count)
var res: [[Int]] = []
backtrack(state: &state, choices: nums, selected: &selected, res: &res)
return res
}
@main
enum PermutationsII {
/* Driver Code */
static func main() {
let nums = [1, 2, 3]
let res = permutationsII(nums: nums)
print("入力配列 nums = \(nums)")
print("すべての順列 res = \(res)")
}
}