Guest User

Untitled

a guest
Oct 15th, 2019
75
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.company;
  2.  
  3. public class ListNode {
  4. int val;
  5. ListNode next;
  6.  
  7. ListNode(int x) {
  8. val = x;
  9. }
  10.  
  11. public ListNode deleteDuplicates(ListNode head) {
  12. while (head.next != null) {
  13. if (head.val == head.next.val) {
  14. head.next = head.next.next;
  15. continue;
  16. }
  17. head = head.next;
  18. }
  19. return null;
  20. }
  21.  
  22.  
  23. @Override
  24. public String toString() {
  25. if (next != null) {
  26. return val + ", " + next;
  27. } return val + "";
  28. }
  29. }
RAW Paste Data