Advertisement
Guest User

Untitled

a guest
Nov 10th, 2019
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1.  
  2. /*
  3. * Complete the 'condense' function below.
  4. *
  5. * The function is expected to return an INTEGER_SINGLY_LINKED_LIST.
  6. * The function accepts INTEGER_SINGLY_LINKED_LIST head as parameter.
  7. */
  8.  
  9. /*
  10. * For your reference:
  11. *
  12. * SinglyLinkedListNode {
  13. * int data;
  14. * SinglyLinkedListNode next;
  15. * }
  16. *
  17. */
  18.  
  19. public static SinglyLinkedListNode condense(SinglyLinkedListNode head) {
  20. if ( head == null ) return null;
  21. Node nextItem = head.next;
  22. while ( nextItem != null && head.data == nextItem.data ) {
  23. nextItem = nextItem.next;
  24. }
  25. head.next = RemoveDuplicates( nextItem );
  26. return head;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement