Class Solution
java.lang.Object
g2401_2500.s2401_longest_nice_subarray.Solution
2401 - Longest Nice Subarray.<p>Medium</p>
<p>You are given an array <code>nums</code> consisting of <strong>positive</strong> integers.</p>
<p>We call a subarray of <code>nums</code> <strong>nice</strong> if the bitwise <strong>AND</strong> of every pair of elements that are in <strong>different</strong> positions in the subarray is equal to <code>0</code>.</p>
<p>Return <em>the length of the <strong>longest</strong> nice subarray</em>.</p>
<p>A <strong>subarray</strong> is a <strong>contiguous</strong> part of an array.</p>
<p><strong>Note</strong> that subarrays of length <code>1</code> are always considered nice.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> nums = [1,3,8,48,10]</p>
<p><strong>Output:</strong> 3</p>
<p><strong>Explanation:</strong> The longest nice subarray is [3,8,48]. This subarray satisfies the conditions:</p>
<ul>
<li>
<p>3 AND 8 = 0.</p>
</li>
<li>
<p>3 AND 48 = 0.</p>
</li>
<li>
<p>8 AND 48 = 0.</p>
</li>
</ul>
<p>It can be proven that no longer nice subarray can be obtained, so we return 3.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> nums = [3,1,5,11,13]</p>
<p><strong>Output:</strong> 1</p>
<p><strong>Explanation:</strong> The length of the longest nice subarray is 1. Any subarray of length 1 can be chosen.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
<li><code>1 <= nums[i] <= 10<sup>9</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
longestNiceSubarray
public int longestNiceSubarray(int[] nums)
-