Skip to content

Commit 68ec3f7

Browse files
committed
Update next-permutation.cpp
1 parent 2c06824 commit 68ec3f7

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

C++/next-permutation.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,20 @@ class Solution {
1818
while (pivot != rend && *pivot >= *prev(pivot)) {
1919
++pivot;
2020
}
21-
21+
22+
bool is_greater = true;
2223
if (pivot != rend) {
2324
// Find the number which is greater than pivot, and swap it with pivot
2425
auto change = find_if(rbegin, pivot, bind1st(less<int>(), *pivot));
2526
swap(*change, *pivot);
27+
} else {
28+
is_greater = false;
2629
}
2730

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

31-
return true;
34+
return is_greater;
3235
}
3336
};
3437

0 commit comments

Comments
 (0)