Easy Solution - C++

programming
Tags: #<Tag:0x00007f2428980708>

#1

int Solution::coverPoints(vector &A, vector &B) {
int ans=0;
int x=A[0],y=B[0];
for(int i=1;i<A.size();i++){
int steps=0;
if(abs(x - A[i])==abs(y - B[i])){
ans+= abs(y-B[i]);
}
else if(abs(x-A[i]) > abs(y - B[i])){
ans+=abs(x - A[i]);
}else{
ans+=abs(y - B[i]);
}
x = A[i];
y = B[i];
}
return ans;
}