Skip to content

Commit

Permalink
Update next-permutation.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
kamyu104 committed Jan 19, 2016
1 parent 0b4415e commit 2ffa843
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions C++/next-permutation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,20 @@ class Solution {
while (pivot != rend && *pivot >= *prev(pivot)) {
++pivot;
}


bool is_greater = true;
if (pivot != rend) {
// Find the number which is greater than pivot, and swap it with pivot
auto change = find_if(rbegin, pivot, bind1st(less<int>(), *pivot));
swap(*change, *pivot);
} else {
is_greater = false;
}

// Make the sequence after pivot non-descending
reverse(rbegin, pivot);

return true;
return is_greater;
}
};

Expand Down

0 comments on commit 2ffa843

Please sign in to comment.