L.ittle
2021-07-24 00:05
采纳率: 0%
浏览 33
已结题

力扣83题,删除链表重复元素

/**

  • Definition for singly-linked list.
  • public class ListNode {
  • int val;
    
  • ListNode next;
    
  • ListNode() {}
    
  • ListNode(int val) { this.val = val; }
    
  • ListNode(int val, ListNode next) { this.val = val; this.next = next; }
    
  • }
  • /
    class Solution {
    public ListNode deleteDuplicates(ListNode head) {
      if(head == null || head.next == null){
          return head;
      }
      ListNode temp = head;
      while( temp.next != null){
          ListNode nex = temp.next;
          while(nex.val == temp.val){
              nex = nex.next;
          }
          temp.next = nex;
          temp = nex;
      }
      return head;
    
    }
    }

//只要碰到{1,2,2}{1,1,1}这种 结尾几个重复的试例就不行

  • 点赞
  • 收藏

相关推荐 更多相似问题