leetcode83,删除有序链表中的重复元素
生活随笔
收集整理的這篇文章主要介紹了
leetcode83,删除有序链表中的重复元素
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
Given a sorted linked list, delete all duplicates such that each element appear only once.
For example,
Given 1->1->2, return 1->2.
Given 1->1->2->3->3, return 1->2->3.
?
難點就一個,就是要考慮到連續(xù)3個和3個以上的情況。
?
/*** Definition for singly-linked list.* public class ListNode {* int val;* ListNode next;* ListNode(int x) { val = x; }* }*/ public class Solution {public ListNode deleteDuplicates(ListNode head) {if(head != null){ListNode nodeA = head;ListNode nodeB = head.next;while(nodeB != null){if(nodeA.val == nodeB.val){nodeA.next = nodeB.next;nodeB = nodeB.next;}else{nodeA = nodeB;nodeB = nodeB.next;}}}return head;} }轉載于:https://www.cnblogs.com/linkstar/p/5995066.html
總結
以上是生活随笔為你收集整理的leetcode83,删除有序链表中的重复元素的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python 列表自定义排序_自定义排序
- 下一篇: 阿里巴巴矢量图标库的使用