-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay13.cpp
77 lines (46 loc) · 1.29 KB
/
Day13.cpp
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define bug cout <<"-----------------"<<endl
/// tomake ekta number deya ache string hisebe , tomake eikhan theke K ta digit remove kore number take jotota somvob choto banaite hobe
/// https://www.youtube.com/watch?v=FKfNLtdLEeQ&feature=youtu.be
class Solution
{
public:
string removeKdigits(string str, int k)
{
if(k==str.length())return "0";
if(str.length()==0)
return "0";
stack < char > st ;
for(int i = 0 ; i < str.length() ; i++)
{
while( !st.empty() and k > 0 and st.top() > str[i] )
{
st.pop();
k--;
}
st.push(str[i]);
}
while(!st.empty()and k--)
{
// cout << st.top() <<" ";
st.pop();
}
string ans = "";
while(!st.empty())
{
ans+=st.top();
st.pop();
}
reverse(ans.begin(), ans.end());
// cout << ans <<endl;
while(ans.length()>1 and ans[0]=='0')
ans.erase(0,1);
return ans;
}
};
int main()
{
return 0;
}