1550. Three Consecutive Odds
UnknownView on LeetCode
Time: O(n)
Space: O(1)
Advertisement
Approach
Linear scan counting consecutive odd numbers; reset on even.
Key Techniques
Array
Array problems involve manipulating elements stored in a contiguous block of memory. Key techniques include two-pointer traversal, prefix sums, sliding windows, and in-place partitioning. In C#, arrays are zero-indexed and fixed in size — use List<T> when you need dynamic resizing.
1550.cs
C#
// Approach: Linear scan counting consecutive odd numbers; reset on even.
// Time: O(n) Space: O(1)
public class Solution
{
public bool ThreeConsecutiveOdds(int[] arr)
{
int cnt = 0;
for (int i = 0; i < arr.Length; i++)
{
if (arr[i] % 2 > 0)
cnt++;
else
cnt = 0;
if (cnt == 3)
return true;
}
return false;
}
}Advertisement
Was this solution helpful?