Skip to content

Commit

Permalink
Create reaching-points.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
kamyu104 authored Feb 11, 2018
1 parent 7b73da5 commit 6e95065
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions C++/reaching-points.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Time: O(log(max(m, n)))
// Space: O(1)

class Solution {
public:
bool reachingPoints(int sx, int sy, int tx, int ty) {
while (tx >= sx && ty >= sy) {
if (tx < ty) {
swap(sx, sy);
swap(tx, ty);
}
if (ty > sy) {
tx %= ty;
} else {
return (tx - sx) % ty == 0;
}
}
return false;
}
};

0 comments on commit 6e95065

Please sign in to comment.