We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent eaf0345 commit ef7418fCopy full SHA for ef7418f
src/_DataStructures_/Stack/ remove-consecutive-repeated-digits/index.js
@@ -0,0 +1,25 @@
1
+/**
2
+ * Given an integer N, remove consecutive repeated digits from it.
3
+ * Input:133445
4
+ * Output:1345
5
+ */
6
+
7
+const Stack = require('../index');
8
9
10
+function removeConsecutiveDigits(no) {
11
+ let s = new Stack();
12
+ let newNo = "";
13
+ //initally push first digit into stack
14
+ newNo += no[0];
15
+ s.push(no[0]);
16
+ for (let i = 1; i < no.length; i++) {
17
+ const digit = no[i];
18
+ //if stack top and incoming digit is same ignore it else append to newNo.
19
+ if (s.peek() !== digit) {
20
+ newNo += digit;
21
+ s.push(digit);
22
+ }
23
24
+ return newNo
25
+}
0 commit comments