Skip to content

Commit 2b145db

Browse files
authoredMay 26, 2019
Create 1047-remove-all-adjacent-duplicates-in-string.js
1 parent df18fe5 commit 2b145db

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* @param {string} S
3+
* @return {string}
4+
*/
5+
const removeDuplicates = function(S) {
6+
const queue = []
7+
for(let i = 0; i < S.length; i++) {
8+
if(queue.length > 0 && queue[queue.length - 1] === S[i]) {
9+
queue.pop()
10+
} else {
11+
queue.push(S[i])
12+
}
13+
}
14+
return queue.join('')
15+
};

0 commit comments

Comments
 (0)
Please sign in to comment.