Created
October 21, 2019 02:44
-
-
Save surinoel/702c2e057a39b5b3c54a9f7314230d65 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stack> | |
#include <string> | |
#include <vector> | |
using namespace std; | |
string solution(string number, int k) { | |
string answer = ""; | |
int len = number.length(); | |
stack<char> st; | |
for (int i = 0; i < len; i++) { | |
char num = number[i]; | |
while (!st.empty() && k > 0) { | |
char tp = st.top(); | |
if (tp < num) { | |
st.pop(); | |
k--; | |
} | |
else { | |
break; | |
} | |
} | |
st.push(num); | |
} | |
while (k > 0) { | |
st.pop(); | |
k--; | |
} | |
while (!st.empty()) { | |
answer = st.top() + answer; | |
st.pop(); | |
} | |
return answer; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment