Today write code encountered this problem
void nextPermutation(vector<int>& nums) {
int start = bigFlow(nums);
sort(nums.begin() + start + 1, nums.end()); //报错行
}
This function is given iterator bounds addition, because my bigFlow()
function returns a value between -1 ~ n, so iterator interval should be between 1-n. That statement is a compiler error to calculate the numss.begin()+start
time if start=-1
so, obviously iterator has been cross-border, in the absence of calculation +1
before the compiler will report an error.
Correction: brackets nums.begin()+(start+1)
, or adjust the order of additionnums.begin()+1+start