mirror of
https://github.com/krahets/hello-algo.git
synced 2026-11-01 18:55:23 +08:00
* feat(ko): add the complete Korean online edition * Use UTF-8 for Python CI output on Windows * Remove print-book promotion from the Korean site * fix(ko): preserve emphasis before Korean particles
32 lines
638 B
Go
32 lines
638 B
Go
// File: list_node.go
|
|
// Created Time: 2022-11-25
|
|
// Author: Reanon ([email protected])
|
|
|
|
package pkg
|
|
|
|
// ListNode: 연결 리스트 노드
|
|
type ListNode struct {
|
|
Next *ListNode
|
|
Val int
|
|
}
|
|
|
|
// NewListNode: 연결 리스트 노드 생성자
|
|
func NewListNode(v int) *ListNode {
|
|
return &ListNode{
|
|
Next: nil,
|
|
Val: v,
|
|
}
|
|
}
|
|
|
|
// ArrayToLinkedList: 배열을 역직렬화하여 연결 리스트로 만든다
|
|
func ArrayToLinkedList(arr []int) *ListNode {
|
|
// 연결 리스트의 더미 머리 노드
|
|
dummy := NewListNode(0)
|
|
node := dummy
|
|
for _, val := range arr {
|
|
node.Next = NewListNode(val)
|
|
node = node.Next
|
|
}
|
|
return dummy.Next
|
|
}
|