Codeforces Round #310 (Div. 2) A. Case of the Zeros and Ones

原题:http://codeforces.com/contest/556/problem/A


题目大意:给一个字符串,如果出现一个0和一个1就同时消除, 问最少剩下几个.


分析: – – 0和1的个数差几个就剩下几个啊..

  public void solve(int testNumber, InputReader in, OutputWriter out) {
        int n = in.readInt();
        int res = 0;
        String s = in.readLine();
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == '0')
                res ++;
            if (s.charAt(i) == '1')
                res --;
        }
        out.print(Math.abs(res));
    }