forked from Thelalitagarwal/GFG_Daily_Problem
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGeek and Number String.cpp
More file actions
32 lines (32 loc) · 875 Bytes
/
Geek and Number String.cpp
File metadata and controls
32 lines (32 loc) · 875 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
class Solution{
public:
bool ischeck(string s){
return (s=="12" || s=="21" ||s=="34" ||s=="43" ||s=="56" ||s=="65" ||s=="78" ||s=="87" ||s=="09" ||s=="90");
}
int minLength(string s, int n) {
stack<char>stk;
for(int i=0;i<n;i++){
stk.push(s[i]);
}
stack<char>help;
while(!stk.empty()){
if(!help.empty()){
string x={stk.top()};
string y={help.top()};
string z=x+y;
if(ischeck(z)){
help.pop();
}
else{
help.push(stk.top());
}
stk.pop();
}
else{
help.push(stk.top());
stk.pop();
}
}
return help.size();
}
};