Skip to content

Commit db06aa8

Browse files
committed
Time: 649 ms (5.05%), Space: 280 MB (5.69%) - LeetHub
1 parent 31d1154 commit db06aa8

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* Definition for singly-linked list.
3+
* struct ListNode {
4+
* int val;
5+
* ListNode *next;
6+
* ListNode() : val(0), next(nullptr) {}
7+
* ListNode(int x) : val(x), next(nullptr) {}
8+
* ListNode(int x, ListNode *next) : val(x), next(next) {}
9+
* };
10+
*/
11+
class Solution {
12+
public:
13+
map<int, bool> mp;
14+
15+
ListNode* modifiedList(vector<int>& nums, ListNode* head) {
16+
for (auto& i : nums) {
17+
mp[i] = true;
18+
}
19+
return solve(head);
20+
}
21+
22+
ListNode* solve(ListNode* head) {
23+
if (!head) return nullptr;
24+
if (mp[head->val]) {
25+
return solve(head->next);
26+
} else {
27+
head->next = solve(head->next);
28+
return head;
29+
}
30+
}
31+
};

0 commit comments

Comments
 (0)