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
+33
View File
@@ -0,0 +1,33 @@
/**
* File: ListNode.swift
* Created Time: 2023-01-02
* Author: nuomi1 (nuomi1@qq.com)
*/
public class ListNode: Hashable {
public var val: Int //
public var next: ListNode? //
public init(x: Int) {
val = x
}
public static func == (lhs: ListNode, rhs: ListNode) -> Bool {
lhs.val == rhs.val && lhs.next.map { ObjectIdentifier($0) } == rhs.next.map { ObjectIdentifier($0) }
}
public func hash(into hasher: inout Hasher) {
hasher.combine(val)
hasher.combine(next.map { ObjectIdentifier($0) })
}
public static func arrToLinkedList(arr: [Int]) -> ListNode? {
let dum = ListNode(x: 0)
var head: ListNode? = dum
for val in arr {
head?.next = ListNode(x: val)
head = head?.next
}
return dum.next
}
}
+20
View File
@@ -0,0 +1,20 @@
/**
* File: Pair.swift
* Created Time: 2023-06-28
* Author: nuomi1 (nuomi1@qq.com)
*/
/* */
public class Pair: Equatable {
public var key: Int
public var val: String
public init(key: Int, val: String) {
self.key = key
self.val = val
}
public static func == (lhs: Pair, rhs: Pair) -> Bool {
lhs.key == rhs.key && lhs.val == rhs.val
}
}
+93
View File
@@ -0,0 +1,93 @@
/**
* File: PrintUtil.swift
* Created Time: 2023-01-02
* Author: nuomi1 (nuomi1@qq.com)
*/
public enum PrintUtil {
private class Trunk {
var prev: Trunk?
var str: String
init(prev: Trunk?, str: String) {
self.prev = prev
self.str = str
}
}
public static func printLinkedList(head: ListNode) {
var head: ListNode? = head
var list: [String] = []
while head != nil {
list.append("\(head!.val)")
head = head?.next
}
print(list.joined(separator: " -> "))
}
public static func printTree(root: TreeNode?) {
printTree(root: root, prev: nil, isRight: false)
}
private static func printTree(root: TreeNode?, prev: Trunk?, isRight: Bool) {
if root == nil {
return
}
var prevStr = " "
let trunk = Trunk(prev: prev, str: prevStr)
printTree(root: root?.right, prev: trunk, isRight: true)
if prev == nil {
trunk.str = "———"
} else if isRight {
trunk.str = "/———"
prevStr = " |"
} else {
trunk.str = "\\———"
prev?.str = prevStr
}
showTrunks(p: trunk)
print(" \(root!.val)")
if prev != nil {
prev?.str = prevStr
}
trunk.str = " |"
printTree(root: root?.left, prev: trunk, isRight: false)
}
private static func showTrunks(p: Trunk?) {
if p == nil {
return
}
showTrunks(p: p?.prev)
print(p!.str, terminator: "")
}
public static func printHashMap<K, V>(map: [K: V]) {
for (key, value) in map {
print("\(key) -> \(value)")
}
}
public static func printHeap(queue: [Int]) {
print("ヒープの配列表現:", terminator: "")
print(queue)
print("ヒープの木構造表現:")
let root = TreeNode.listToTree(arr: queue)
printTree(root: root)
}
public static func printMatrix<T>(matrix: [[T]]) {
print("[")
for row in matrix {
print(" \(row),")
}
print("]")
}
}
+71
View File
@@ -0,0 +1,71 @@
/**
* File: TreeNode.swift
* Created Time: 2023-01-02
* Author: nuomi1 (nuomi1@qq.com)
*/
/* */
public class TreeNode {
public var val: Int //
public var height: Int //
public var left: TreeNode? //
public var right: TreeNode? //
/* */
public init(x: Int) {
val = x
height = 0
}
// :
// https://www.hello-algo.com/chapter_tree/array_representation_of_tree/
// :
// [1, 2, 3, 4, nil, 6, 7, 8, 9, nil, nil, 12, nil, nil, 15]
// :
// / 15
// / 7
// / 3
// | \\ 6
// | \\ 12
// 1
// \\ 2
// | / 9
// \\ 4
// \\ 8
/* : */
private static func listToTreeDFS(arr: [Int?], i: Int) -> TreeNode? {
if i < 0 || i >= arr.count || arr[i] == nil {
return nil
}
let root = TreeNode(x: arr[i]!)
root.left = listToTreeDFS(arr: arr, i: 2 * i + 1)
root.right = listToTreeDFS(arr: arr, i: 2 * i + 2)
return root
}
/* */
public static func listToTree(arr: [Int?]) -> TreeNode? {
listToTreeDFS(arr: arr, i: 0)
}
/* : */
private static func treeToListDFS(root: TreeNode?, i: Int, res: inout [Int?]) {
if root == nil {
return
}
while i >= res.count {
res.append(nil)
}
res[i] = root?.val
treeToListDFS(root: root?.left, i: 2 * i + 1, res: &res)
treeToListDFS(root: root?.right, i: 2 * i + 2, res: &res)
}
/* */
public static func treeToList(root: TreeNode?) -> [Int?] {
var res: [Int?] = []
treeToListDFS(root: root, i: 0, res: &res)
return res
}
}
+32
View File
@@ -0,0 +1,32 @@
/**
* File: Vertex.swift
* Created Time: 2023-02-19
* Author: nuomi1 (nuomi1@qq.com)
*/
/* */
public class Vertex: Hashable {
public var val: Int
public init(val: Int) {
self.val = val
}
public static func == (lhs: Vertex, rhs: Vertex) -> Bool {
lhs.val == rhs.val
}
public func hash(into hasher: inout Hasher) {
hasher.combine(val)
}
/* vals vets */
public static func valsToVets(vals: [Int]) -> [Vertex] {
vals.map { Vertex(val: $0) }
}
/* vets vals */
public static func vetsToVals(vets: [Vertex]) -> [Int] {
vets.map { $0.val }
}
}