最长优雅子数组 (Longest Nice Subarray)

 

思路:

// @Title: 最长优雅子数组 (Longest Nice Subarray)
// @Author: qisiii
// @Date: 2024-09-11 19:35:40
// @Runtime: 5 ms
// @Memory: 54.7 MB
// @comment: 
// @flag: 
class Solution {
    public int longestNiceSubarray(int[] nums) {
        int left=0,right=0,len=0;
        while(right<nums.length){
            if(!checkPerfer(left,right,nums)){
                left++;
            }else{
                len=Math.max(len,right-left+1);
                right++;
            }
        }
        return len;
    }
    boolean checkPerfer(int left,int right,int[] nums){
        if(left>right){
            return false;
        }
        if(left==right){
            return true;
        }
        for(;left<right;left++){
            for(int j=left+1;j<=right;j++){
                if((nums[left]&nums[right])!=0){
                    return false;
                }
            }
        }
        return true;
    }
}
Licensed under CC BY-NC-SA 4.0
最后更新于 2024-10-18