2 Approaches || Easy || Beats 100%
\n# Approach 1\n Describe your approach to solving the problem. \n\n# Complexity\n- Time complexity:\n Add your time complexity here, e.g. O(n) \nO(N)\n\n- Spac
![image.png](https://assets.leetcode.com/users/images/23edaab9-1981-4d97-b13b-5f72e1d27c91_1728444291.3986533.png)\n# Approach 1\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(N)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(1)\n# Code\n```cpp []\nclass Solution {\npublic:\n    long long minimumSteps(string s) {\n        long long ans=0,c=0;\n        for(int i=0;i<s.size();i++){\n            if(s[i]==\'1\') c++;\n            else ans+=c;\n        }\n        return ans;\n    }\n};\n```\n\n# Approach 2\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(N)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(1)\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    long long minimumSteps(string s) {\n        long long ans=0,c=0;\n        for(int i=s.size()-1;i>=0;i--){\n            if(s[i]==\'0\') c++;\n            else ans+=c;\n        }\n        return ans;\n    }\n};\n```\n![image.png](https://assets.leetcode.com/users/images/23edaab9-1981-4d97-b13b-5f72e1d27c91_1728444291.3986533.png)
['Array', 'Two Pointers', 'String', 'Greedy', 'Counting', 'Python', 'C++', 'Java', 'Python3', 'JavaScript']