Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd33a25f

Browse files
add 1836
1 parente9dedf2 commitd33a25f

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+
packagecom.fishercoder.solutions;
2+
3+
importcom.fishercoder.common.classes.ListNode;
4+
5+
importjava.util.HashMap;
6+
importjava.util.Map;
7+
8+
publicclass_1836 {
9+
publicstaticclassSolution1 {
10+
publicListNodedeleteDuplicatesUnsorted(ListNodehead) {
11+
Map<Integer,Integer>map =newHashMap<>();
12+
ListNodetmp =head;
13+
while (tmp !=null) {
14+
map.put(tmp.val,map.getOrDefault(tmp.val,0) +1);
15+
tmp =tmp.next;
16+
}
17+
ListNodepre =newListNode(-1);
18+
tmp =pre;
19+
while (head !=null) {
20+
if (map.get(head.val) ==1) {
21+
tmp.next =newListNode(head.val);
22+
tmp =tmp.next;
23+
}
24+
head =head.next;
25+
}
26+
returnpre.next;
27+
}
28+
}
29+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
packagecom.fishercoder;
2+
3+
importcom.fishercoder.common.utils.LinkedListUtils;
4+
importcom.fishercoder.solutions._1836;
5+
importorg.junit.BeforeClass;
6+
importorg.junit.Test;
7+
8+
importstaticorg.junit.Assert.assertEquals;
9+
10+
publicclass_1836Test {
11+
privatestatic_1836.Solution1solution1;
12+
13+
@BeforeClass
14+
publicstaticvoidsetup() {
15+
solution1 =new_1836.Solution1();
16+
}
17+
18+
@Test
19+
publicvoidtest1() {
20+
assertEquals(LinkedListUtils.contructLinkedList(newint[]{1,3}),solution1.deleteDuplicatesUnsorted(LinkedListUtils.contructLinkedList(newint[]{1,2,3,2})));
21+
}
22+
23+
@Test
24+
publicvoidtest2() {
25+
assertEquals(LinkedListUtils.contructLinkedList(newint[]{}),solution1.deleteDuplicatesUnsorted(LinkedListUtils.contructLinkedList(newint[]{2,1,1,2})));
26+
}
27+
28+
@Test
29+
publicvoidtest3() {
30+
assertEquals(LinkedListUtils.contructLinkedList(newint[]{1,4}),solution1.deleteDuplicatesUnsorted(LinkedListUtils.contructLinkedList(newint[]{3,2,2,1,3,2,4})));
31+
}
32+
33+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp