java.lang.Object
g1401_1500.s1460_make_two_arrays_equal_by_reversing_sub_arrays.Solution

public class Solution extends Object
1460 - Make Two Arrays Equal by Reversing Sub-arrays.<p>Easy</p> <p>You are given two integer arrays of equal length <code>target</code> and <code>arr</code>. In one step, you can select any <strong>non-empty sub-array</strong> of <code>arr</code> and reverse it. You are allowed to make any number of steps.</p> <p>Return <code>true</code> <em>if you can make</em> <code>arr</code> <em>equal to</em> <code>target</code><em>or</em> <code>false</code> <em>otherwise</em>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> target = [1,2,3,4], arr = [2,4,1,3]</p> <p><strong>Output:</strong> true</p> <p><strong>Explanation:</strong> You can follow the next steps to convert arr to target:</p> <p>1- Reverse sub-array [2,4,1], arr becomes [1,4,2,3]</p> <p>2- Reverse sub-array [4,2], arr becomes [1,2,4,3]</p> <p>3- Reverse sub-array [4,3], arr becomes [1,2,3,4]</p> <p>There are multiple ways to convert arr to target, this is not the only way to do so.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> target = [7], arr = [7]</p> <p><strong>Output:</strong> true</p> <p><strong>Explanation:</strong> arr is equal to target without any reverses.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> target = [3,7,9], arr = [3,7,11]</p> <p><strong>Output:</strong> false</p> <p><strong>Explanation:</strong> arr does not have value 9 and it can never be converted to target.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>target.length == arr.length</code></li> <li><code>1 <= target.length <= 1000</code></li> <li><code>1 <= target[i] <= 1000</code></li> <li><code>1 <= arr[i] <= 1000</code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • canBeEqual

      public boolean canBeEqual(int[] target, int[] arr)