Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public ListNode deleteDuplicates(ListNode head) {
- if (head == null) {
- return head;
- }
- ListNode current = head;
- while (current != null) {
- ListNode next = findNext(current);
- current.next = next;
- current = next;
- }
- return head;
- }
- private static ListNode findNext(ListNode node) {
- ListNode next = node.next;
- while (next != null && node.val == next.val) {
- next = next.next;
- }
- return next;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement