Skip to content

Instantly share code, notes, and snippets.

@pinkmomo027
Created June 18, 2018 17:53
Show Gist options
  • Save pinkmomo027/2827dbb34938261e2a8c75a2b6467e02 to your computer and use it in GitHub Desktop.
Save pinkmomo027/2827dbb34938261e2a8c75a2b6467e02 to your computer and use it in GitHub Desktop.
delete consecutive strings
// https://www.geeksforgeeks.org/delete-consecutive-words-sequence/
function deleteConsecutive(arr) {
let stack = new Stack();
arr.forEach(element => {
if (element == stack.peek()) {
stack.pop();
} else {
stack.push(element);
}
});
return stack.size();
}
console.log(deleteConsecutive(['ab', 'aa', 'aa', 'bcd', 'ab',]));
console.log(deleteConsecutive(['tom', 'jerry', 'jerry', 'tom',]));
@pinkmomo027
Copy link
Author

3
0
[Finished in 0.2s]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment