I'm trying to do this Leetcode challenge:
Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.
But I'm getting this error:
Line 10: Char 28: error: no viable conversion from returned value of type 'int [2]' to function return type 'vector'
On this statement:
return arrayresult;
Here is my code:
class Solution {
public:
vector<int> twoSum(vector<int>& nums, int target) {
for (int i = 0; i < sizeof(nums); i++)
for (int j = 0; j < sizeof(nums); j++)
if (i != j){
int result = nums[i] + nums[j];
if (result == target){
int arrayresult[] = {i,j}; //Line 10
return arrayresult;
}
}
}
};
Example 1:
Input: nums = [2,7,11,15], target = 9
Output: [0,1]
Output: Because nums[0] + nums[1] == 9, we return [0, 1].