this is the problem of leetcode..problem is to find the next permutation. it passes correctly on sample test cases but it shows error in line 1034 which is not even in the code..!! plz help
error code is-------
Line 1034: Char 34: runtime error: addition of unsigned offset to 0x602000000170 overflowed to 0x60200000016c (stl_vector.h) SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/stl_vector.h:1043:34
class Solution {
public:
void nextPermutation(vector<int>& nums)
{
int n = nums.size();
int i=0,j=0;
for(i=n-2;i>=0;i--)
{
if(nums[i]<nums[i+1])
break;
}
if(i<0)
sort(nums.begin(),nums.end());
else
{
for(j=n-1;j>i;j--)
{
if(nums[j]>nums[i])
break;
}
}
swap(nums[i],nums[j]);
sort(nums.begin()+i+1,nums.end());
}
};
Aucun commentaire:
Enregistrer un commentaire