Advertisement
Guest User

Untitled

a guest
Feb 17th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. /**
  2. * Definition for singly-linked list.
  3. * public class ListNode {
  4. * int val;
  5. * ListNode next;
  6. * ListNode(int x) { val = x; }
  7. * }
  8. */
  9. class Solution {
  10. public ListNode deleteDuplicates(ListNode head) {
  11. if(head == null || head.next == null) return head;
  12. ListNode cur = head;
  13. ListNode next = head.next;
  14. while(cur != null){
  15. while(next != null && next.val == cur.val){
  16. next = next.next;
  17. }
  18. cur.next = next;
  19. cur = cur.next;
  20. }
  21. return head;
  22. }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement