You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
531 B
25 lines
531 B
/**
|
|
* 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
|
|
}
|
|
}
|