You are viewing a single comment's thread. Return to all comments →
U can use while loop instead of for....
int p=x1,n=x2; if((x1==x2 && v1!=v2) || (x2>x1 && v2>v1) || (x1>x2 && v1>v2)) return "NO"; else { while(p!=n) { p=p+v1; n=n+v2; if(p>n) { return "NO"; } else if(p==n) { return "YES"; } } } return "NO";
Seems like cookies are disabled on this browser, please enable them to open this website
Number Line Jumps
You are viewing a single comment's thread. Return to all comments →
U can use while loop instead of for....
int p=x1,n=x2; if((x1==x2 && v1!=v2) || (x2>x1 && v2>v1) || (x1>x2 && v1>v2)) return "NO"; else { while(p!=n) { p=p+v1; n=n+v2; if(p>n) { return "NO"; } else if(p==n) { return "YES"; } } } return "NO";