Skip to content

Commit 5de6f21

Browse files
authored
Create RemoveDuplicatesLL.java
1 parent 4f9a819 commit 5de6f21

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

RemoveDuplicatesLL.java

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Definition for singly-linked list.
3+
* public class ListNode {
4+
* int val;
5+
* ListNode next;
6+
* ListNode() {}
7+
* ListNode(int val) { this.val = val; }
8+
* ListNode(int val, ListNode next) { this.val = val; this.next = next; }
9+
* }
10+
*/
11+
class Solution {
12+
public ListNode deleteDuplicates(ListNode head) {
13+
//handling edge cases
14+
if(head==null)
15+
return null;
16+
// creating temp variabe to keep track
17+
ListNode temp = head;
18+
while(temp.next!=null){
19+
if(temp.val== temp.next.val)
20+
temp.next=temp.next.next;
21+
else
22+
temp = temp.next;
23+
}
24+
return head;
25+
26+
}
27+
}

0 commit comments

Comments
 (0)