code? Like in the below code, time complexity is O(n) but wht abt the value of this term "no of operations"?
class Solution {
public:
void moveZeroes(vector<int>& nums) {
int j = 0;
int cnt = 0;
for(int i=0; i<nums.size(); i++)
{
if(nums[i]!=0)
{
nums[j] = nums[i];
j++;
}
else
cnt++;
}
for(int i = 1; i<=cnt; i++)
nums[nums.size()-1-cnt+i] = 0;
}
};
Are you trying to write a program that does that or are you trying to find out how many instructions your program actually uses?
I have written a program to solve a question but I am not trying to find it's instruction cycle
operations is a loose term here as you would in English
Обсуждают сегодня