mercredi 17 mars 2021

leetcode Runtime error: addition of unsigned offset

I was solving a question on Leetcode(Next Permutation)

class Solution {
    public:
        void nextPermutation(vector<int>& nums) {
            int i=nums.size()-2;
            while(i>=0 && nums[i]>nums[i+1])
            { 
                i--;
            }
            int j=nums.size()-1;
            if(i>=0)
            {
                while(j>=0 && nums[j]<=nums[i]){
                    j--;
                }
                swap(nums[i],nums[j]);
            }
            reverse(nums.begin()+i+1,nums.end());
            
        }
    };

This is the only part i had to edit. And upon running it i'm getting the following error

Line 1034: Char 34: runtime error: addition of unsigned offset to 0x602000000470 overflowed to 0x60200000046c (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

Aucun commentaire:

Enregistrer un commentaire