C++ 代码
#include <iostream>
using namespace std;
const int N = 2e5 + 10;
char a[N]; // 数组模拟栈
int r = 0;
int main(){
int n;
string s;
cin >> n >> s;
for(char c : s){
if(r == 0) {
a[r ++] = c;
}else{
if(c == a[r - 1]) a[r ++] = c;
else -- r;
}
}
cout << r << endl;
return 0;
}