From 80ed826176fcb3d353172601f92b179c915c3216 Mon Sep 17 00:00:00 2001 From: chayan das <110921638+Chayandas07@users.noreply.github.com> Date: Sat, 2 Nov 2024 01:28:01 +0530 Subject: [PATCH] Create 1957. Delete Characters to Make Fancy String --- 1957. Delete Characters to Make Fancy String | 36 ++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 1957. Delete Characters to Make Fancy String diff --git a/1957. Delete Characters to Make Fancy String b/1957. Delete Characters to Make Fancy String new file mode 100644 index 0000000..77c7b3f --- /dev/null +++ b/1957. Delete Characters to Make Fancy String @@ -0,0 +1,36 @@ +class Solution { +public: + string makeFancyString(string s) { + stackst; + for(int i = 0;i=3){ + char first = st.top(); + st.pop(); + char second = st.top(); + st.pop(); + char third = st.top(); + st.pop(); + if(first == second && second == third){ + + st.push(second); + st.push(first); + }else{ + + st.push(third); + st.push(second); + st.push(first); + } + } + } + + string ans = ""; + while(!st.empty()){ + ans += st.top(); + st.pop(); + + } + reverse(ans.begin(),ans.end()); + return ans; + } +};