Skip to content

Commit d33a25f

Browse files
add 1836
1 parent e9dedf2 commit d33a25f

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ _If you like this project, please leave me a star._ ★
4949
|1845|[Seat Reservation Manager](https://leetcode.com/problems/seat-reservation-manager/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1845.java) ||Medium|Heap, Design|
5050
|1844|[Replace All Digits with Characters](https://leetcode.com/problems/replace-all-digits-with-characters/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1844.java) ||Easy|String|
5151
|1837|[Sum of Digits in Base K](https://leetcode.com/problems/sum-of-digits-in-base-k/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1837.java) ||Easy|Math, Bit Manipulation|
52+
|1836|[Remove Duplicates From an Unsorted Linked List](https://leetcode.com/problems/remove-duplicates-from-an-unsorted-linked-list/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1836.java) ||Medium|HashTable, LinkedList|
5253
|1833|[Maximum Ice Cream Bars](https://leetcode.com/problems/maximum-ice-cream-bars/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1833.java) ||Medium|Array, Sort|
5354
|1832|[Check if the Sentence Is Pangram](https://leetcode.com/problems/check-if-the-sentence-is-pangram/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1832.java) ||Easy|String|
5455
|1829|[Maximum XOR for Each Query](https://leetcode.com/problems/maximum-xor-for-each-query/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1829.java) ||Medium|Bit Manipulation|
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.fishercoder.solutions;
2+
3+
import com.fishercoder.common.classes.ListNode;
4+
5+
import java.util.HashMap;
6+
import java.util.Map;
7+
8+
public class _1836 {
9+
public static class Solution1 {
10+
public ListNode deleteDuplicatesUnsorted(ListNode head) {
11+
Map<Integer, Integer> map = new HashMap<>();
12+
ListNode tmp = head;
13+
while (tmp != null) {
14+
map.put(tmp.val, map.getOrDefault(tmp.val, 0) + 1);
15+
tmp = tmp.next;
16+
}
17+
ListNode pre = new ListNode(-1);
18+
tmp = pre;
19+
while (head != null) {
20+
if (map.get(head.val) == 1) {
21+
tmp.next = new ListNode(head.val);
22+
tmp = tmp.next;
23+
}
24+
head = head.next;
25+
}
26+
return pre.next;
27+
}
28+
}
29+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.common.utils.LinkedListUtils;
4+
import com.fishercoder.solutions._1836;
5+
import org.junit.BeforeClass;
6+
import org.junit.Test;
7+
8+
import static org.junit.Assert.assertEquals;
9+
10+
public class _1836Test {
11+
private static _1836.Solution1 solution1;
12+
13+
@BeforeClass
14+
public static void setup() {
15+
solution1 = new _1836.Solution1();
16+
}
17+
18+
@Test
19+
public void test1() {
20+
assertEquals(LinkedListUtils.contructLinkedList(new int[]{1, 3}), solution1.deleteDuplicatesUnsorted(LinkedListUtils.contructLinkedList(new int[]{1, 2, 3, 2})));
21+
}
22+
23+
@Test
24+
public void test2() {
25+
assertEquals(LinkedListUtils.contructLinkedList(new int[]{}), solution1.deleteDuplicatesUnsorted(LinkedListUtils.contructLinkedList(new int[]{2, 1, 1, 2})));
26+
}
27+
28+
@Test
29+
public void test3() {
30+
assertEquals(LinkedListUtils.contructLinkedList(new int[]{1, 4}), solution1.deleteDuplicatesUnsorted(LinkedListUtils.contructLinkedList(new int[]{3, 2, 2, 1, 3, 2, 4})));
31+
}
32+
33+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy