You are viewing a single comment's thread. Return to all comments →
c++ solution, disliking the fact that I spent a bit too long thinking about how to do this, no cause the problem explenation sucks.
string biggerIsGreater(string w) { int n = w.length(); int i = n - 2; while (i >= 0 && w[i] >= w[i + 1]) { i--; } if (i < 0) return "no answer"; int j = n - 1; while (w[j] <= w[i]) { j--; } swap(w[i], w[j]); reverse(w.begin() + i + 1, w.end()); return w; }
Seems like cookies are disabled on this browser, please enable them to open this website
Bigger is Greater
You are viewing a single comment's thread. Return to all comments →
c++ solution, disliking the fact that I spent a bit too long thinking about how to do this, no cause the problem explenation sucks.