82. 删除排序链表中的重复元素 II🔖链表

82. 删除排序链表中的重复元素 II🔖链表

bug原因:在使用 axios 的拦截器时,没有添加返回值  return  config解决方法:在请求拦截器中添加 return config,  (!!!注意响应拦截器中也要添加返回值)

2021年11月17日
106字
7 阅读


typescript

/**
 * Definition for singly-linked list.
 * class ListNode {
 *     val: number
 *     next: ListNode | null
 *     constructor(val?: number, next?: ListNode | null) {
 *         this.val = (val===undefined ? 0 : val)
 *         this.next = (next===undefined ? null : next)
 *     }
 * }
 */

function deleteDuplicates(head: ListNode | null): ListNode | null {
  if (!head) return head
  const firstNode = new ListNode(-1, head);
  let curr = firstNode;
  while (curr.next && curr.next.next) {
    if (curr.next.val === curr.next.next.val) {
      const temp = curr.next.val
      while (curr.next && curr.next.val === temp)
        curr.next = curr.next.next;
    } else {
      curr = curr.next;
    }
  }
  return firstNode.next;
};

文章评论区

欢迎留言交流

未登录,请先注册或登录后发表评论。

Leave comment