// defining a linked list using nested object let LL = {data: 1, next: {data: 2, next: {data: 3, next: {data: 1, next: {data: 2, next: {data: 5, next: null}}}}}}; let buffer = []; // an empty buffer to store values and check duplicates let HEAD = LL; // pointing to top of the linked list. let prev = null; // to store previous node while(HEAD != null) { if(buffer.indexOf(HEAD.data)>-1) { prev.next = HEAD.next; } else { buffer.push(HEAD.data); prev = HEAD; } HEAD = HEAD.next; } console.log(LL);
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (0)