Files
hello-algo/ja/codes/javascript/modules/ListNode.js
T
Yudong JinandClaude Opus 5.5 ded7ddc635 Revert the runnable-snippets batches to the #2033 state (#2038)
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]>
2026-11-16 06:45:32 +08:00

32 lines
724 B
JavaScript

/**
* File: ListNode.js
* Created Time: 2022-12-12
* Author: IsChristina ([email protected])
*/
/* 連結リストのノード */
class ListNode {
val; // ノードの値
next; // 次のノードへの参照(ポインタ)
constructor(val, next) {
this.val = val === undefined ? 0 : val;
this.next = next === undefined ? null : next;
}
}
/* リストをデシリアライズして連結リストにする */
function arrToLinkedList(arr) {
const dum = new ListNode(0);
let head = dum;
for (const val of arr) {
head.next = new ListNode(val);
head = head.next;
}
return dum.next;
}
module.exports = {
ListNode,
arrToLinkedList,
};