js Linked List Generator All In One
js 链表生成器
class ListNode {
constructor(val, next) {
this.val = (val===undefined ? 0 : val)
this.next = (next===undefined ? null : next)
}
// add
// remove
}
function LinkedListGenerator(arr) {
let head;
const len = arr.length;
for (let i = 0; i < len; i++) {
if(i === 0) {
head = new ListNode(arr[len - 1 - i], null);
} else {
let temp = new ListNode(arr[len - 1 - i], null);
temp.next = head;
head = temp;
}
}
// console.log(head);
return head;
}
LinkedListGenerator([1,2,3,4,5])
LeetCode 算法题解 / 链表
https://www.cnblogs.com/xgqfrms/tag/算法题解/
https://www.cnblogs.com/xgqfrms/tag/链表/
LeetCode 合并两个有序链表算法题解 All In One
https://www.cnblogs.com/xgqfrms/p/16633129.html
LeetCode 重排链表算法题解 All In One
https://www.cnblogs.com/xgqfrms/p/16618119.html
refs
©xgqfrms 2012-2020
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 ️,侵权必究⚠️!