Skip to content

Commit a805db4

Browse files
authored
Create reaching-points.cpp
1 parent ec1645a commit a805db4

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

C++/reaching-points.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Time: O(log(max(m, n)))
2+
// Space: O(1)
3+
4+
class Solution {
5+
public:
6+
bool reachingPoints(int sx, int sy, int tx, int ty) {
7+
while (tx >= sx && ty >= sy) {
8+
if (tx < ty) {
9+
swap(sx, sy);
10+
swap(tx, ty);
11+
}
12+
if (ty > sy) {
13+
tx %= ty;
14+
} else {
15+
return (tx - sx) % ty == 0;
16+
}
17+
}
18+
return false;
19+
}
20+
};

0 commit comments

Comments
 (0)