Skip to content

Commit

Permalink
Merge pull request #26 from atulgoel126/main-q82
Browse files Browse the repository at this point in the history
Added solution for Q82 - Remove dupes from sorted list, updated README
  • Loading branch information
atulgoel126 authored Aug 1, 2024
2 parents 6d456fd + 16cdefa commit d165c25
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 35 deletions.
39 changes: 19 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ This setup provides a comprehensive structure and automation for practicing codi
## My Study Plan

### Heap/Priority Queue (10 Medium Questions)
1. **Question #347 (Medium)** - Top K Frequent Elements
1. **Question #347 (Medium)** - Top K Frequent Elements
2. **Question #692 (Medium)** - Top K Frequent Words
3. **Question #451 (Medium)** - Sort Characters By Frequency
4. **Question #973 (Medium)** - K Closest Points to Origin
Expand All @@ -133,20 +133,19 @@ This setup provides a comprehensive structure and automation for practicing codi
10. **Question #759 (Medium)** - Employee Free Time

### Sorting/Searching (5 Medium Questions)
1. **Question #34 (Medium)** - Find First and Last Position of Element in Sorted Array
2. **Question #347 (Medium)** - Top K Frequent Elements
3. **Question #658 (Medium)** - Find K Closest Elements
4. **Question #912 (Medium)** - Sort an Array
5. **Question #162 (Medium)** - Find Peak Element
1. ✅ **Question #34 (Medium)** - Find First and Last Position of Element in Sorted Array
2. ✅ **Question #658 (Medium)** - Find K Closest Elements
3. ✅ **Question #912 (Medium)** - Sort an Array
4. ✅ **Question #162 (Medium)** - Find Peak Element

### Dijkstra's Algorithm (3 Questions)
1. **Question #743 (Medium)** - Network Delay Time
2. **Question #787 (Medium)** - Cheapest Flights Within K Stops
3. **Question #1631 (Medium)** - Path With Minimum Effort

### Prim's Algorithm (2 Questions)
1. **Question #1584 (Medium)** - Min Cost to Connect All Points
2. **Question #1135 (Medium)** - Connecting Cities With Minimum Cost
1. **Question #1584 (Medium)** - Min Cost to Connect All Points
2. **Question #1135 (Medium)** - Connecting Cities With Minimum Cost

### Union Find (4 Questions)
1. **Question #684 (Medium)** - Redundant Connection
Expand Down Expand Up @@ -204,7 +203,7 @@ This setup provides a comprehensive structure and automation for practicing codi
8. **Question #152 (Medium)** - Maximum Product Subarray

### Recursion with Strings (5 Questions)
1. **Question #22 (Medium)** - Generate Parentheses
1. **Question #22 (Medium)** - Generate Parentheses
2. **Question #44 (Hard)** - Wildcard Matching
3. **Question #93 (Medium)** - Restore IP Addresses
4. **Question #131 (Medium)** - Palindrome Partitioning
Expand Down Expand Up @@ -248,9 +247,9 @@ This setup provides a comprehensive structure and automation for practicing codi
4. **Question #567 (Medium)** - Permutation in String

### Matrix (5 Questions)
1. **Question #36 (Medium)** - Valid Sudoku
2. **Question #54 (Medium)** - Spiral Matrix
3. **Question #48 (Medium)** - Rotate Image
1. **Question #36 (Medium)** - Valid Sudoku
2. **Question #54 (Medium)** - Spiral Matrix
3. **Question #48 (Medium)** - Rotate Image
4. **Question #73 (Medium)** - Set Matrix Zeroes
5. **Question #289 (Medium)** - Game of Life

Expand Down Expand Up @@ -282,13 +281,13 @@ This setup provides a comprehensive structure and automation for practicing codi
### Linked List (10 Questions)

1. **Question #141 (Easy)** - Linked List Cycle
2. **Question #2 (Medium)** - Add Two Numbers
2. **Question #2 (Medium)** - Add Two Numbers
3. **Question #21 (Easy)** - Merge Two Sorted Lists
4. **Question #138 (Medium)** - Copy List with Random Pointer
5. **Question #92 (Medium)** - Reverse Linked List II
6. **Question #25 (Hard)** - Reverse Nodes in k-Group
7. **Question #19 (Medium)** - Remove Nth Node From End of List
8. **Question #82 (Medium)** - Remove Duplicates from Sorted List II
7. **Question #19 (Medium)** - Remove Nth Node From End of List
8. **Question #82 (Medium)** - Remove Duplicates from Sorted List II
9. **Question #61 (Medium)** - Rotate List
10. **Question #86 (Medium)** - Partition List

Expand All @@ -309,10 +308,10 @@ This setup provides a comprehensive structure and automation for practicing codi
4. **Question #417 (Medium)** - Pacific Atlantic Water Flow

### Misc Questions
1. **Question #72 (Medium)** - Edit Distance
2. **Question #146 (Medium)** - LRU Cache
3. **Question #200 (Medium)** - Number of Islands
4. **Question #938 (Easy)** - Range Sum of BST
1. **Question #72 (Medium)** - Edit Distance
2. **Question #146 (Medium)** - LRU Cache
3. **Question #200 (Medium)** - Number of Islands
4. **Question #938 (Easy)** - Range Sum of BST

## Total - 145 problems
## Completed - 7 problems
## Completed - 18 problems
Original file line number Diff line number Diff line change
@@ -1,6 +1,33 @@
package leetcode.linked_list.q82;

import leetcode.commons.ListNode;

public class RemoveDuplicatesfromSortedListII {
// public ListNode deleteDuplicates(ListNode head) {
// return null;
// }
public ListNode deleteDuplicates(ListNode head) {

if (head == null || head.next == null) {
return head;
}

ListNode dummy = new ListNode(-1);
dummy.next = head;

ListNode prev = dummy;
ListNode curr = head;

// -1-> 1 -> 1 -> 1 -> 2 -> 3 -> 3
// p c c.n
while (curr != null && curr.next != null) {
if (curr.val == curr.next.val) {
while (curr.next != null && curr.val == curr.next.val) {
curr = curr.next;
}
prev.next = curr.next;
} else {
prev = prev.next;
}
curr = curr.next;
}
return dummy.next;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package leetcode.linked_list.q82;

import static org.junit.jupiter.api.Assertions.*;

import leetcode.linked_list.q82.RemoveDuplicatesfromSortedListII;
import leetcode.commons.ListNode;
import org.junit.jupiter.api.Test;

class RemoveDuplicatesfromSortedListIITests {
Expand Down Expand Up @@ -68,8 +70,8 @@ void testNoDuplicateElements() {

private void removeDuplicatesAndAssert(ListNode head, ListNode expected) {
RemoveDuplicatesfromSortedListII ob = new RemoveDuplicatesfromSortedListII();
// ListNode actual = ob.deleteDuplicates(head);
// assertListNodeEquals(expected, actual);
ListNode actual = ob.deleteDuplicates(head);
assertListNodeEquals(expected, actual);
}

private void assertListNodeEquals(ListNode expected, ListNode actual) {
Expand All @@ -86,13 +88,4 @@ private void assertListNodeEquals(ListNode expected, ListNode actual) {
assertNull(expected);
assertNull(actual);
}
}

class ListNode {
int val;
ListNode next;

ListNode(int val) {
this.val = val;
}
}

0 comments on commit d165c25

Please sign in to comment.