mirror of
https://github.com/krahets/hello-algo.git
synced 2026-11-02 03:05:24 +08:00
* 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
32 lines
724 B
JavaScript
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,
|
|
};
|