This content originally appeared on DEV Community and was authored by NJ
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode() {}
* ListNode(int val) { this.val = val; }
* ListNode(int val, ListNode next) { this.val = val; this.next = next; }
* }
*/
class Solution {
public ListNode deleteDuplicates(ListNode head) {
ListNode temp = head;
if(temp==null){
return temp;
}else if(temp.next==null){
return temp;
}
ListNode prev = temp;
temp = temp.next;
while(temp!=null){
if(temp.val == prev.val){
prev.next = temp.next;
temp = temp.next;
}else{
prev = temp;
temp = temp.next;
}
}
return head;
}
}
This content originally appeared on DEV Community and was authored by NJ
Print
Share
Comment
Cite
Upload
Translate
Updates
There are no updates yet.
Click the Upload button above to add an update.

APA
MLA
NJ | Sciencx (2023-05-01T14:47:58+00:00) 83. Remove Duplicates from Sorted List leetcode solution in java. Retrieved from https://www.scien.cx/2023/05/01/83-remove-duplicates-from-sorted-list-leetcode-solution-in-java/
" » 83. Remove Duplicates from Sorted List leetcode solution in java." NJ | Sciencx - Monday May 1, 2023, https://www.scien.cx/2023/05/01/83-remove-duplicates-from-sorted-list-leetcode-solution-in-java/
HARVARDNJ | Sciencx Monday May 1, 2023 » 83. Remove Duplicates from Sorted List leetcode solution in java., viewed ,<https://www.scien.cx/2023/05/01/83-remove-duplicates-from-sorted-list-leetcode-solution-in-java/>
VANCOUVERNJ | Sciencx - » 83. Remove Duplicates from Sorted List leetcode solution in java. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2023/05/01/83-remove-duplicates-from-sorted-list-leetcode-solution-in-java/
CHICAGO" » 83. Remove Duplicates from Sorted List leetcode solution in java." NJ | Sciencx - Accessed . https://www.scien.cx/2023/05/01/83-remove-duplicates-from-sorted-list-leetcode-solution-in-java/
IEEE" » 83. Remove Duplicates from Sorted List leetcode solution in java." NJ | Sciencx [Online]. Available: https://www.scien.cx/2023/05/01/83-remove-duplicates-from-sorted-list-leetcode-solution-in-java/. [Accessed: ]
rf:citation » 83. Remove Duplicates from Sorted List leetcode solution in java | NJ | Sciencx | https://www.scien.cx/2023/05/01/83-remove-duplicates-from-sorted-list-leetcode-solution-in-java/ |
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.