hello-algo/codes/swift/utils/ListNode.swift
Yudong Jin 1c8b7ef559
refactor: Replace 结点 with 节点 (#452)
* Replace 结点 with 节点
Update the footnotes in the figures

* Update mindmap

* Reduce the size of the mindmap.png
2023-04-09 04:32:17 +08:00

24 lines
531 B
Swift

/**
* File: ListNode.swift
* Created Time: 2023-01-02
* Author: nuomi1 (nuomi1@qq.com)
*/
public class ListNode {
public var val: Int //
public var next: ListNode? //
public init(x: Int) {
val = x
}
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
}
}