3152. Special Array II | Daily LeetCode Solution | Java

  Рет қаралды 170

AlgoXploration

AlgoXploration

Күн бұрын

Пікірлер: 1
@AlgoXploration
@AlgoXploration 8 күн бұрын
class Solution { public boolean[] isArraySpecial(int[] nums, int[][] queries) { int n = nums.length; int m = queries.length; //Processing: Create a parityMisMatch array boolean[] parityMismatch = new boolean[n-1]; for(int i = 0; i < n-1; i++) parityMismatch[i] = (nums[i] % 2 == nums[i+1] % 2); //Create the prefix sum of mismatches int[] prefix = new int[n]; for(int i = 1; i < n; i++) prefix[i] = prefix[i-1] + (parityMismatch[i-1] ? 1 : 0); //Process the queries boolean[] result = new boolean[m]; for(int i = 0; i < m; i++) { int from = queries[i][0]; int to = queries[i][1]; // If there's any mismatch in the range [from, to - 1], the subarray is not special result[i] = (from == to) || (prefix[to] - prefix[from] == 0); } return result; } }
Why I’m Switching To Go in 2024
8:10
Awesome
Рет қаралды 96 М.
How many people are in the changing room? #devil #lilith #funny #shorts
00:39
Beat Ronaldo, Win $1,000,000
22:45
MrBeast
Рет қаралды 156 МЛН
She made herself an ear of corn from his marmalade candies🌽🌽🌽
00:38
Valja & Maxim Family
Рет қаралды 17 МЛН
Cat mode and a glass of water #family #humor #fun
00:22
Kotiki_Z
Рет қаралды 37 МЛН
TypeScript теперь в CSS?! Это как?
9:12
Как пройти в IT?
Рет қаралды 9 М.
Why Is Lua So Popular?
8:03
Awesome
Рет қаралды 101 М.
Special Array II | Leetcode 3152
13:49
Techdose
Рет қаралды 4,2 М.
How to Start Leetcode (as a beginner)
8:45
Ashish Pratap Singh
Рет қаралды 1 МЛН
How many people are in the changing room? #devil #lilith #funny #shorts
00:39