Source Code
#include <iostream>

using namespace std;
int a[1000100];
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];
    int o=0;
    int z=0;
    int ans=0;
    for(int i=0;i<n;i++)
    {
        if(a[i]==0)
            z++;
        if(a[i]==1)
            o++;
        if(z&&o)
        {
            z=0;
            o=0;
            ans++;
            o =0;
            z=0;
        }

    }
    cout<<ans<<endl;

}
Copy
Tha Bits CR7
GNU G++17
15 ms
1.1 MB
Accepted