In the leetcode probelm : https://leetcode.com/problems/rotate-array/
Why this is showing error. I called rotate function in the same manner as discussed in video i.e.
rotate(nums.begin(), nums.begin()+k, nums.end());
In the leetcode probelm : https://leetcode.com/problems/rotate-array/
Why this is showing error. I called rotate function in the same manner as discussed in video i.e.
rotate(nums.begin(), nums.begin()+k, nums.end());
@vaishnavtannu i dont think you can use rotate stl in this as function name is also rotate therefore will throw error
The error is something like too many arguments.
The problem with the name of the function can be easily solved using another utility function and calling that in rotate function.
But error is related to syntax i guess…
@vaishnavtannu so try changing the function name as the stl is working fine (arguments error is because of that rotate function void as defined in leetcode)
void rotateUtil(vector<int>& nums, int k)
{
rotate(nums.begin(), nums.begin()+k, nums.end());
}
void rotate(vector<int>& nums, int k)
{
rotateUtil(nums, k);
}
Even this is giving error.
ok got it. thanks…
k=k%nums.size();
::rotate(nums.begin(),nums.begin()+nums.size()-k,nums.end());
This worked !