Created
June 18, 2018 17:53
-
-
Save pinkmomo027/2827dbb34938261e2a8c75a2b6467e02 to your computer and use it in GitHub Desktop.
delete consecutive strings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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',])); |
Author
pinkmomo027
commented
Jun 18, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment