Skip to content

Instantly share code, notes, and snippets.

@Jonniie
Created February 1, 2025 23:10
Show Gist options
  • Save Jonniie/e5950845692ca103ce348a4dda88d72a to your computer and use it in GitHub Desktop.
Save Jonniie/e5950845692ca103ce348a4dda88d72a to your computer and use it in GitHub Desktop.
Leetcode Day 1

Question

Approach

My approach was to loop through the nums arr and check the equality of the parities of adjacent elements, so it checks if elements at i and i+1 are either both even or both odd

Implementation

class Solution {
public:
    bool isArraySpecial(vector<int>& nums) {
        for(int i = 0; i < nums.size() - 1; i++) {
            if(nums.at(i) % 2 == nums.at(i+1) % 2) {
                return false;
            }
        }

        return true;
    }
};

Complexities

  • Time: O(n)
  • Space: O(1)

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment