题目
  1. 给定一个已排序的链表的头 head , 删除所有重复的元素,使每个元素只出现一次 。返回 已排序的链表 。
代码
/**
 * 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 {
   
       const FinallyVal: ListNode = head
       while(head && head.next && head.next.next) {
   
           if(head.val === head.next.val) {
   
               head.next = head.next.next
           }else {
   
               head = head.next
           }
          
       }
       if(head && head.next && head.val === head.next.val) {
   
           head.next = null
       }
       return FinallyVal
};

📦 前端资源合集 | 持续更新

🟢 前端0到1【持续更新】→ https://pan.quark.cn/s/5df55ccff7c4

🔵 前端进阶【持续更新】→ https://pan.quark.cn/s/2dec1c87b3ec

🟣 前端2026最新【持续更新】→ https://pan.quark.cn/s/77c8fa94161c

🔴 AI最新学习资料 → https://pan.baidu.com/s/1P9X2Qk_Fby3rFNVGw_WKow?pwd=46XG 提取码:46XG

觉得有用就点个赞+收藏,关注我持续分享前端干货 💡

Logo

AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。

更多推荐