An alerting tool wants to highlight error codes that happened exactly once, since repeated codes are already known issues. The codes come as a linked list sorted from smallest to largest.
Write keepOneOffs(head) that removes every node whose value appears more than once (all of its copies, not just the extras), and returns the head of what is left. If nothing is left, return null.
Input: head = [1,2,3,3,4,4,5] Output: [1,2,5]
3 and 4 repeat, so every copy of them goes.
Input: head = [1,1,1,2,3] Output: [2,3]
All three 1s go, even though they start the list.
0 to 300 nodes.-100 <= node.val <= 100Lists are written as arrays here, like [1, 2, 3]. Your function works with ListNode objects, each with val and next.
Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #226 Keep Only One-Off Codes. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.