📌  相关文章
📜  第 24 天:更多链表hackerrank 解决方案 javascript 代码示例

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

代码示例2
// 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;
};