feat: add Swift codes for linked_list article

This commit is contained in:
nuomi1
2023-01-08 20:22:59 +08:00
parent 230c7723d5
commit 7556558704
4 changed files with 173 additions and 3 deletions

View File

@@ -15,6 +15,16 @@ public enum PrintUtil {
}
}
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, isLeft: false)
}