Skip to content

Commit fa7ac1b

Browse files
solves remove duplicates from linkedlist
1 parent 4639059 commit fa7ac1b

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
| 66 | [Plus One](https://leetcode.com/problems/plus-one) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/PlusOne.java) |
3030
| 67 | [Add Binary](https://leetcode.com/problems/add-binary) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/AddBinary.java) |
3131
| 69 | [Sqrt(x)](https://leetcode.com/problems/sqrtx) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/Sqrtx.java) |
32-
| 70 | [Climbing Stairs](https://leetcode.com/problems/climbing-stairs) | Easy | |
32+
| 70 | [Climbing Stairs](https://leetcode.com/problems/climbing-stairs) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/ClimbingStairs.java) |
3333
| 83 | [Remove Duplicates from Sorted List](https://leetcode.com/problems/remove-duplicates-from-sorted-list) | Easy | |
3434
| 88 | [Merge Sorted Array](https://leetcode.com/problems/merge-sorted-array) | Easy | |
3535
| 100 | [Same Tree](https://leetcode.com/problems/same-tree) | Easy | |
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
public class RemoveDuplicatesFromSortedList {
2+
public static class ListNode {
3+
int val;
4+
ListNode next;
5+
6+
ListNode() {
7+
}
8+
9+
ListNode(int val) {
10+
this.val = val;
11+
}
12+
13+
ListNode(int val, ListNode next) {
14+
this.val = val;
15+
this.next = next;
16+
}
17+
}
18+
19+
public ListNode deleteDuplicates(ListNode head) {
20+
ListNode current = head;
21+
while (current != null) {
22+
if (current.next != null && current.next.val == current.val) {
23+
current.next = current.next.next;
24+
} else {
25+
current = current.next;
26+
}
27+
}
28+
return head;
29+
}
30+
}

0 commit comments

Comments
 (0)