Files
hello-algo/ja/codes/javascript/modules/ListNode.js
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

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,
};