diff --git a/cs/ListNode.cs b/cs/ListNode.cs new file mode 100644 index 0000000..6309468 --- /dev/null +++ b/cs/ListNode.cs @@ -0,0 +1,9 @@ +public class ListNode { + public int val; + public ListNode? next; + + public ListNode(int val = 0, ListNode? next = null) { + this.val = val; + this.next = next; + } +} diff --git a/cs/delete-nodes-from-linked-list-present-in-array.cs b/cs/delete-nodes-from-linked-list-present-in-array.cs new file mode 100644 index 0000000..7ea8440 --- /dev/null +++ b/cs/delete-nodes-from-linked-list-present-in-array.cs @@ -0,0 +1,21 @@ +using System.Collections.Generic; + +public class Solution { + public ListNode ModifiedList(int[] nums, ListNode head) { + var uniqueNums = new HashSet(nums); + + var node = head; + while (node.next != null) { + if (uniqueNums.Contains(node.next.val)) { + node.next = node.next.next; + } else { + node = node.next; + } + } + + if (uniqueNums.Contains(head.val)) { + return head.next; + } + return head; + } +}