java.lang.Object
g2501_2600.s2543_check_if_point_is_reachable.Solution

public class Solution extends Object
2543 - Check if Point Is Reachable.<p>Hard</p> <p>There exists an infinitely large grid. You are currently at point <code>(1, 1)</code>, and you need to reach the point <code>(targetX, targetY)</code> using a finite number of steps.</p> <p>In one <strong>step</strong> , you can move from point <code>(x, y)</code> to any one of the following points:</p> <ul> <li><code>(x, y - x)</code></li> <li><code>(x - y, y)</code></li> <li><code>(2 * x, y)</code></li> <li><code>(x, 2 * y)</code></li> </ul> <p>Given two integers <code>targetX</code> and <code>targetY</code> representing the X-coordinate and Y-coordinate of your final position, return <code>true</code> <em>if you can reach the point from</em> <code>(1, 1)</code> <em>using some number of steps, and</em> <code>false</code> <em>otherwise</em>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> targetX = 6, targetY = 9</p> <p><strong>Output:</strong> false</p> <p><strong>Explanation:</strong> It is impossible to reach (6,9) from (1,1) using any sequence of moves, so false is returned.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> targetX = 4, targetY = 7</p> <p><strong>Output:</strong> true</p> <p><strong>Explanation:</strong> You can follow the path (1,1) -> (1,2) -> (1,4) -> (1,8) -> (1,7) -> (2,7) -> (4,7).</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= targetX, targetY <= 10<sup>9</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • isReachable

      public boolean isReachable(int x, int y)