A log viewer stores error codes in a linked list sorted from smallest to largest. Many lines share the same code, and the summary panel should show each code only once.
Write collapseCodes(head) that removes repeated nodes so each value appears exactly once, and returns the head. The list stays sorted. Reuse the existing nodes.
Input: head = [1,1,2] Output: [1,2]
The second 1 is a repeat, so it goes.
Input: head = [1,1,2,3,3] Output: [1,2,3]
One 1 and one 3 are removed.
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 #225 Collapse Repeated Log 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.