#include<iostream>
#include<string>
#include<stack>
using namespace std;
int main(){
int n, x, ans = 0;
string str;
stack<int> st;
cin >> n >> str;
for(int i = 0; i < n; ++i){
x = str[i] - '0';
if(st.empty()) st.push(x);
else if(st.top() != x) st.pop(), ans += 2;
else st.push(x);
}
cout << n-ans <<endl;
return 0;
}
the Zeros and Ones
最新推荐文章于 2022-04-07 10:37:37 发布