📌  相关文章
📜  第 15 天:链表hackerrank javascript 解决方案 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:24.338000             🧑  作者: Mango

代码示例1
// Day 15: Linked List hackerrank javascript solution
this.insert = function (head, data) {
  //complete this method
  let newNode = new Node(data);
  if (head === null || typeof head === "undefined") {
    head = newNode;
  } else if (head.next === null) {
    head.next = newNode;
  } else {
    let nextValue = head.next;
    while (nextValue.next) {
      nextValue = nextValue.next;
    }
    nextValue.next = newNode;
  }
  return head;
};