java.lang.Object
g1801_1900.s1814_count_nice_pairs_in_an_array.Solution

public class Solution extends Object
1814 - Count Nice Pairs in an Array.<p>Medium</p> <p>You are given an array <code>nums</code> that consists of non-negative integers. Let us define <code>rev(x)</code> as the reverse of the non-negative integer <code>x</code>. For example, <code>rev(123) = 321</code>, and <code>rev(120) = 21</code>. A pair of indices <code>(i, j)</code> is <strong>nice</strong> if it satisfies all of the following conditions:</p> <ul> <li><code>0 <= i < j < nums.length</code></li> <li><code>nums[i] + rev(nums[j]) == nums[j] + rev(nums[i])</code></li> </ul> <p>Return <em>the number of nice pairs of indices</em>. Since that number can be too large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> nums = [42,11,1,97]</p> <p><strong>Output:</strong> 2</p> <p><strong>Explanation:</strong> The two pairs are:</p> <ul> <li> <p>(0,3) : 42 + rev(97) = 42 + 79 = 121, 97 + rev(42) = 97 + 24 = 121.</p> </li> <li> <p>(1,2) : 11 + rev(1) = 11 + 1 = 12, 1 + rev(11) = 1 + 11 = 12.</p> </li> </ul> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> nums = [13,10,35,24,76]</p> <p><strong>Output:</strong> 4</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= nums.length <= 10<sup>5</sup></code></li> <li><code>0 <= nums[i] <= 10<sup>9</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • countNicePairs

      public int countNicePairs(int[] nums)