Skip to content

Commit

Permalink
Solution to #13
Browse files Browse the repository at this point in the history
  • Loading branch information
bharatr21 committed May 14, 2020
1 parent ec4f4e8 commit cdbdb18
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Solutions/S13.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
string removeKdigits(string num, int k) {
int n = num.size();
char c;
if(k >= n) return "0";
for(int i = 0; i < k; i++)
{
int j = 0;
while(j < n - 1 && num[j] <= num[j + 1]) j++;
num.erase(num.begin() + j, num.begin() + j + 1);
}

//Remove leading zeros
while(num.size() > 1 && num[0] == '0') num.erase(num.begin(), num.begin() + 1);

return num;
}

0 comments on commit cdbdb18

Please sign in to comment.