We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents f3a6642 + 80ed826 commit 8f06d05Copy full SHA for 8f06d05
1957. Delete Characters to Make Fancy String
@@ -0,0 +1,36 @@
1
+class Solution {
2
+public:
3
+ string makeFancyString(string s) {
4
+ stack<char>st;
5
+ for(int i = 0;i<s.length();i++){
6
+ st.push(s[i]);
7
+ if(st.size()>=3){
8
+ char first = st.top();
9
+ st.pop();
10
+ char second = st.top();
11
12
+ char third = st.top();
13
14
+ if(first == second && second == third){
15
+
16
+ st.push(second);
17
+ st.push(first);
18
+ }else{
19
20
+ st.push(third);
21
22
23
+ }
24
25
26
27
+ string ans = "";
28
+ while(!st.empty()){
29
+ ans += st.top();
30
31
32
33
+ reverse(ans.begin(),ans.end());
34
+ return ans;
35
36
+};
0 commit comments