I am new to Vector while solving Twosum problem from leetcode, encountered following Compilation error :
Line 4: Char 26: error: no viable conversion from 'std::vector<int, std::allocator<int>>::iterator' (aka '__normal_iterator<int *, std::vector<int, std::allocator<int>>>') to 'unsigned int'
for(unsigned int i=nums.begin();i<nums.end();i++)
Here is my code:
class Solution {
public:
vector<int> twoSum(vector<int>& nums, int target) {
for(unsigned int i=nums.begin();i<nums.end();i++)
{
for(int j=i+1;j<=nums.end();j++)
{
if(nums[i]+nums[j]==target)
{
vector<int> vec;
vec[0]=i;
vec[1]=j;
break;
}
}
}
return vec;
}
};
I tried googling this but didn't get much. Just wanted to know what does this error mean and how to fix it.