You are viewing a single comment's thread. Return to all comments →
string biggerIsGreater(string w) { int target = -1; int target2 = -1; for(int i=w.size()-1;i>=0;i--){ if(w[i]-'a'>w[i-1]-'a'){ target = i-1; break; } } if(target==-1){ return "no answer"; } for(int i=w.size()-1;i>=0;i--){ if(w[i]-'a'>w[target]-'a'){ target2=i; break; } } swap(w[target],w[target2]); reverse(w.begin()+target+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 →