Files
hello-algo/ja/codes/csharp/utils/ListNode.cs
T
Yudong Jin 7257641e0e Retranslate the complete Japanese online edition from Chinese (#2008)
* Retranslate the complete Japanese online edition from Chinese

* Fit Japanese homepage labels and localize heading permalinks

* Point Japanese contribution instructions to the Japanese preview

* Replace locale conditionals with multilingual UI tables
2026-10-30 02:12:26 +08:00

33 lines
836 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);
}
}