C++ count & loop||beats 100%
Intuition\n Describe your first thoughts on how to solve this problem. \nCount \'1\' in s & let it be n1. Let n0=n-n1.\n# Approach\n Describe your approach to s
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nCount `\'1\'` in `s` & let it be `n1`. Let `n0=n-n1`.\n# Approach\n<!-- Describe your approach to solving the problem. -->\nUse the loop for `i<n0` do `ans-=i`\nUse the loop for `i>=n0` do `ans+=i`\nReturn `ans`!\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$O(n)$$\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n$$O(1)$$\n# Code\n```\n#pragma GCC optimize("O3")\nclass Solution {\npublic:\n    long long minimumSteps(string& s) {\n        int n=s.size();\n        int n1=count(s.begin(), s.end(), \'1\'), n0=n-n1;\n    //    cout<<"n1="<<n1<<", n0="<<n0<<endl;\n        long long ans=0;\n        #pragma unroll\n        for(int i=0; i<n0; i++)\n            if (s[i]==\'1\') ans-=i;\n        #pragma unroll\n        for(int i=n0; i<n; i++)\n            if (s[i]==\'0\') ans+=i;\n        return ans;\n    }\n};\nauto init = []()\n{ \n    ios::sync_with_stdio(0);\n    cin.tie(0);\n    cout.tie(0);\n    return \'c\';\n}();\n```
['C++']