Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. https://leetcode.com/problems/remove-duplicates-from-sorted-list/description/
  2.  
  3. public ListNode deleteDuplicates(ListNode head) {
  4. if(head == null || head.next == null){
  5. return head;
  6. }
  7. ListNode curr = head;
  8.  
  9. while(curr.next != null){
  10. if(curr.val == curr.next.val){
  11. curr.next = curr.next.next;
  12. }
  13. else{
  14. curr = curr.next;
  15. }
  16. }
  17. if(curr.val == head.val){
  18. head.next = null;
  19. }
  20. return head;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement