C++ solution, long but easy


#1

int Solution::coverPoints(vector &A, vector &B) {
int s = 0;
int p,q,x,y;
int* gr;
int* sm;

for(int i = 1; i < A.size(); i++)
{
    gr = &A[i];
    sm = &B[i];
    if(B[i] > A[i])
    swap(gr, sm);

    p = (*gr - *(gr - 1));
    q = (*sm - *(sm - 1));
    x = abs(p);
    y =  abs(q);

   if(x <= 1 && y <= 1)
   {
    if(x != y)
    {
        s += abs(x-y);
    }
    else if(x==y)
    s += abs(x);
}
if(x > 1 || y > 1)
{
    if(y>x)
        swap(x, y);
    s += x;

}
}
return s;

}