mirror of
https://gitlab.com/mfocko/LeetCode.git
synced 2024-11-14 18:07:32 +01:00
22 lines
524 B
C#
22 lines
524 B
C#
|
using System.Collections.Generic;
|
||
|
|
||
|
public class Solution {
|
||
|
public ListNode ModifiedList(int[] nums, ListNode head) {
|
||
|
var uniqueNums = new HashSet<int>(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;
|
||
|
}
|
||
|
}
|