Skip to content

Commit

Permalink
2024-09-07 Delete Nodes From Linked List Present in Array
Browse files Browse the repository at this point in the history
  • Loading branch information
InSange committed Sep 6, 2024
1 parent 7517dc6 commit ea88f3d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions InSange/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <vector>
#include <unordered_map>

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<int>& nums, ListNode* head) {
ListNode* removeList = new ListNode();
ListNode* removeHead;
unordered_map<int, bool> 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;
}
};

0 comments on commit ea88f3d

Please sign in to comment.