Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Complete the 'condense' function below.
- *
- * The function is expected to return an INTEGER_SINGLY_LINKED_LIST.
- * The function accepts INTEGER_SINGLY_LINKED_LIST head as parameter.
- */
- /*
- * For your reference:
- *
- * SinglyLinkedListNode {
- * int data;
- * SinglyLinkedListNode next;
- * }
- *
- */
- public static SinglyLinkedListNode condense(SinglyLinkedListNode head) {
- if ( head == null ) return null;
- Node nextItem = head.next;
- while ( nextItem != null && head.data == nextItem.data ) {
- nextItem = nextItem.next;
- }
- head.next = RemoveDuplicates( nextItem );
- return head;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement