标签:bsp val 递归 while public else 返回 style solution
在一个排序的链表中,存在重复的结点,请删除该链表中重复的结点,重复的结点不保留,返回链表头指针。 例如,链表1->2->3->3->4->4->5 处理后为 1->2->5
递归
public class Solution { public ListNode deleteDuplication(ListNode pHead) { if(pHead == null||pHead.next == null) return pHead; if(pHead.val == pHead.next.val){ while(pHead.next.next!=null&&pHead.next.val == pHead.next.next.val){ pHead.next = pHead.next.next; } return deleteDuplication(pHead.next.next); }else{ pHead.next = deleteDuplication(pHead.next); } return pHead; } }
标签:bsp val 递归 while public else 返回 style solution
原文地址:https://www.cnblogs.com/tendermelon/p/12863667.html