So I decided to give the easiest problem on Leetcode a try and since I dont data structures well enough to use maps or hashtables I knew I was gonna have to go for brute force. I am getting this error when I try to compile and it is for my return statements.
Line 9: Char 29: error: expected expression
return nums[] {i,i+1}
^
My code below:
vector<int> twoSum(vector<int>& nums, int target) {
for (int i = 0;i<nums.size();i++){
int ans;
ans = nums[i]+nums[i+1];
if(ans == target)
return nums[] {i,i+1};
else{
for(int j = i+1;j<size() - i; j++){
int ans1;
ans1 = nums[j] == nums[j+1];
i++;
if(ans1 == target)
return nums[] {j,j+1};
}
}
}
}
I am not too sure how I can return the index number of the array, so that was my best go at it.