mirror of
https://github.com/krahets/hello-algo.git
synced 2026-11-02 03:05:24 +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
33 lines
833 B
C#
33 lines
833 B
C#
// File: ListNode.cs
|
|
// Created Time: 2022-12-16
|
|
// Author: mingXta ([email protected])
|
|
|
|
namespace hello_algo.utils;
|
|
|
|
/* 연결 리스트 노드 */
|
|
public class ListNode(int x) {
|
|
public int val = x;
|
|
public ListNode? next;
|
|
|
|
/* 배열을 역직렬화하여 연결 리스트로 변환한다 */
|
|
public static ListNode? ArrToLinkedList(int[] arr) {
|
|
ListNode dum = new(0);
|
|
ListNode head = dum;
|
|
foreach (int val in arr) {
|
|
head.next = new ListNode(val);
|
|
head = head.next;
|
|
}
|
|
return dum.next;
|
|
}
|
|
|
|
public override string? ToString() {
|
|
List<string> list = [];
|
|
var head = this;
|
|
while (head != null) {
|
|
list.Add(head.val.ToString());
|
|
head = head.next;
|
|
}
|
|
return string.Join("->", list);
|
|
}
|
|
}
|