Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- https://leetcode.com/problems/remove-duplicates-from-sorted-list/description/
- public ListNode deleteDuplicates(ListNode head) {
- if(head == null || head.next == null){
- return head;
- }
- ListNode curr = head;
- while(curr.next != null){
- if(curr.val == curr.next.val){
- curr.next = curr.next.next;
- }
- else{
- curr = curr.next;
- }
- }
- if(curr.val == head.val){
- head.next = null;
- }
- return head;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement