Skip to content

Commit 5e210ee

Browse files
add 3217
1 parent e43ff77 commit 5e210ee

File tree

2 files changed

+39
-0
lines changed
  • paginated_contents/algorithms/4th_thousand
  • src/main/java/com/fishercoder/solutions/fourththousand

2 files changed

+39
-0
lines changed

Diff for: paginated_contents/algorithms/4th_thousand/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
| # | Title | Solutions | Video | Difficulty | Tag
22
|------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------|------------|----------------------------------------------------------------------
3+
| 3217 | [Delete Nodes From Linked List Present in Array](https://leetcode.com/problems/delete-nodes-from-linked-list-present-in-array/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3217.java) | | Medium | LinkedList
34
| 3216 | [Lexicographically Smallest String After a Swap](https://leetcode.com/problems/lexicographically-smallest-string-after-a-swap/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3216.java) | | Easy | Greedy
45
| 3212 | [Count Submatrices With Equal Frequency of X and Y](https://leetcode.com/problems/count-submatrices-with-equal-frequency-of-x-and-y/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3212.java) | | Medium | Prefix Sum
56
| 3211 | [Generate Binary Strings Without Adjacent Zeros](https://leetcode.com/problems/generate-binary-strings-without-adjacent-zeros/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3211.java) | | Medium | Recursion, Backtracking
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.fishercoder.solutions.fourththousand;
2+
3+
import com.fishercoder.common.classes.ListNode;
4+
5+
import java.util.ArrayList;
6+
import java.util.HashSet;
7+
import java.util.List;
8+
import java.util.Set;
9+
10+
public class _3217 {
11+
public static class Solution1 {
12+
public ListNode modifiedList(int[] nums, ListNode head) {
13+
Set<Integer> set = new HashSet<>();
14+
for (int num : nums) {
15+
set.add(num);
16+
}
17+
ListNode tmp = head;
18+
List<Integer> list = new ArrayList<>();
19+
while (tmp != null) {
20+
if (!set.contains(tmp.val)) {
21+
list.add(tmp.val);
22+
}
23+
tmp = tmp.next;
24+
}
25+
if (list.size() == 0) {
26+
return null;
27+
}
28+
ListNode pre = new ListNode(-1);
29+
ListNode tmp2 = new ListNode(list.get(0));
30+
pre.next = tmp2;
31+
for (int i = 1; i < list.size(); i++) {
32+
tmp2.next = new ListNode(list.get(i));
33+
tmp2 = tmp2.next;
34+
}
35+
return pre.next;
36+
}
37+
}
38+
}

0 commit comments

Comments
 (0)