Source Code
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1;

void solve() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0 ; i < n ; i++) {
    scanf("%d", &v[i]);
  }
  int answer = 0;
  int last = v[0];
  for (int i = 1 ; i < n ; i++) {
    if (v[i] != last) {
      answer++;
      if (i != n - 1)
        last = v[i + 1];
    }
  }
  cout << answer << endl;
}

int main() {
  int t = 1;
  // cin >> t;
  while (t--) {
    solve();
  }

  return 0;
}
Copy
Tha Bits CPX99
GNU G++17
13 ms
1.6 MB
Accepted