mirror of
https://github.com/krahets/hello-algo.git
synced 2026-11-28 18:02:46 +08:00
Reverts #2034, #2035, #2036 and #2037. The work will return in a single
reviewed PR that is completed before it merges. The tree equals 8c96e2f30
(#2033).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
33 lines
861 B
C#
33 lines
861 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);
|
|
}
|
|
}
|