Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Definition for singly-linked list.
- * public class ListNode {
- * int val;
- * ListNode next;
- * ListNode(int x) { val = x; }
- * }
- */
- class Solution {
- public ListNode deleteDuplicates(ListNode head) {
- if(head == null || head.next == null) return head;
- ListNode cur = head;
- ListNode next = head.next;
- while(cur != null){
- while(next != null && next.val == cur.val){
- next = next.next;
- }
- cur.next = next;
- cur = cur.next;
- }
- return head;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement