mirror of
https://github.com/krahets/hello-algo.git
synced 2026-11-14 01:38:18 +08:00
* Retranslate the complete Japanese online edition from Chinese * Fit Japanese homepage labels and localize heading permalinks * Point Japanese contribution instructions to the Japanese preview * Replace locale conditionals with multilingual UI tables
34 lines
882 B
Swift
34 lines
882 B
Swift
/**
|
||
* 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
|
||
}
|
||
}
|