不粘锅的博客

反装单向链表

function NodeList(key) { this.key = key this.prev = null}class LinkedList { constructor() { this.head = null } insert(node) {

管理员 发布于 2022-07-11

实现一个单向链表

实现起来比较简单,如下demofunction ListNode(key, next = null) { return { key, next }}class LinkedList { constructor() { this.head

管理员 发布于 2022-07-11

数组常用方法的时间复杂度

功能时间复杂度追加O(1)索引O(1)插入O(n)删除O(n)合并O(m+n)为什么追加元素是O(1)的呢?其实数组在内存中是有一段预留空间,如下图示例预留空间其实是有限的,如果空间不足会开辟新的空间

管理员 发布于 2022-07-08