leetcode刷题报错UndefinedBehaviorSanitizer

leetcode刷题报错UndefinedBehaviorSanitizer

class Solution {
public:
    vector twoSum(vector& nums, int target) {
        vector resOut;
        for(int i = 0; i < nums.size(); i++) {
            for(int j = i + 1; j < nums.size(); j++) {
                if((nums[i] + nums[j]) == target) {
                    resOut[0] = i;
                    resOut[1] = j;
                    return resOut;
                }
            }
        }
        return resOut;
    }
};

这个报错提示不提示代码的问题,初次遇到,后来发现是vector直接赋值,应该加上“resOut.resize(2)”

你可能感兴趣的:(杂类,leetcode,职场和发展)