. - 力扣(LeetCode) 先找到奇偶性不同的数据下标,取他们中间的数字 再将需要判断的子数组的下标插入到该奇偶性不同的数组数据中,他们的下标不相同则一定包含了不是特殊数组的值 import bisect from typing import List class Solution: def isArraySpecial(self, nums: List[int], queries: List[List[int]]) -> List[bool]: not_special_index = [] is_odd = nums[0] % 2 == 0 for i in range(1, len(nums)): odd = nums[i] % 2 == 0 if odd == is_odd: not_special_index.append(i - 0.5) is_odd = odd result = [True] * len(queries) if not not_special_index: return result for index, query in enumerate(queries): [start, end] = query start_index = bisect.bisect_left(not_special_index, start) end_index = bisect.bisect_right(not_special_index, end) if start_index != end_index: result[index] = False return result