diff --git a/InSange/README.md b/InSange/README.md index 7d32dac..48462ff 100644 --- a/InSange/README.md +++ b/InSange/README.md @@ -31,6 +31,7 @@ | 27차시 | 2024.08.17 | 문자열 | [Number of Senior Citizens](https://leetcode.com/problems/number-of-senior-citizens/) | [#27](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/91)] | 28차시 | 2024.08.21 | 백트래킹 | [월드컵](https://www.acmicpc.net/problem/6987) | [#28](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/94)] | 29차시 | 2024.08.25 | 문자열 | [Find the Closest Palindrome](https://leetcode.com/problems/find-the-closest-palindrome/) | [#29](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/98)] +| 30차시 | 2024.09.06 | 문자열 | [Delete Nodes From Linked List Present in Array](https://leetcode.com/problems/delete-nodes-from-linked-list-present-in-array/) | [#30](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/100)] --- https://leetcode.com/problems/robot-collisions/ diff --git "a/InSange/\354\227\260\352\262\260 \353\246\254\354\212\244\355\212\270/3217_Delete Nodes From Linked List Present in Array.cpp" "b/InSange/\354\227\260\352\262\260 \353\246\254\354\212\244\355\212\270/3217_Delete Nodes From Linked List Present in Array.cpp" new file mode 100644 index 0000000..7062927 --- /dev/null +++ "b/InSange/\354\227\260\352\262\260 \353\246\254\354\212\244\355\212\270/3217_Delete Nodes From Linked List Present in Array.cpp" @@ -0,0 +1,35 @@ +#include +#include + +using namespace std; + + +struct ListNode { + int val; + ListNode* next; + ListNode() : val(0), next(nullptr) {} + ListNode(int x) : val(x), next(nullptr) {} + ListNode(int x, ListNode* next) : val(x), next(next) {} +}; + +class Solution { +public: + ListNode* modifiedList(vector& nums, ListNode* head) { + ListNode* removeList = new ListNode(); + ListNode* removeHead; + unordered_map um; + + for (int& val : nums) um[val] = true; + + removeList->next = head; + removeHead = removeList; + + while (removeHead->next) + { + if (um[removeHead->next->val] == true) removeHead->next = removeHead->next->next; + else removeHead = removeHead->next; + } + + return removeList->next; + } +}; \ No newline at end of file