You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
int next_permutation(int num[], int len) {
int i = len - 2; // partition number's index
while (i >= 0 && num[i] >= num[i + 1]) i--;
if(i == -1) return 0;
if (i >= 0) {
int j = len - 1; // change number's index
while (num[j] <= num[i]) --j;
swap(num, i, j); reverse(num, i + 1, len);
} else {
reverse(num, i + 1, len);
}
return 1;
这段代码中if(i == -1) return 0;应该去掉吧
如果为-1应该对整个数组逆序,而不是返回.否则最后面的else子句根本不会执行
求确认
The text was updated successfully, but these errors were encountered:
这段代码中if(i == -1) return 0;应该去掉吧
如果为-1应该对整个数组逆序,而不是返回.否则最后面的else子句根本不会执行
求确认
The text was updated successfully, but these errors were encountered: