Hello
I am doing this question on leetcode…
1171. Remove Zero Sum Consecutive Nodes from Linked List
I have attempted it with two-three approaches, But it is showing wrong answer of some .
How should i approach this?
What should be the logic.
Thanks
Not getting the logic
@ashishnnnnn
Algorithm
- Iterate LinkedList from left to right
- Process each accumulative value in this datastructure. (unordered_map<int,ListNode*>um) um[ac] = currentNode;
- Given a current accumulative value check if exists in our map (get previous element).
- If they exist um[ac]->next = currentNode->next, then delete intermediate nodes in our map between um[ac] and currentNode
this problem is somewhat similar to subarrays with sum = 0.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.