Greedy Easy Solution | 1ms Beats 100%
Complexity\n- Time complexity: O(N)\n\n- Space complexity:O(1)\n\n# Code\npython []\nclass Solution(object):\n    def lemonadeChange(self, bills):\n        if b
# Complexity\n- Time complexity: O(N)\n\n- Space complexity:O(1)\n\n# Code\n``` python []\nclass Solution(object):\n    def lemonadeChange(self, bills):\n        if bills[0] != 5:\n            return False\n        \n        five_dollers = 0\n        ten_dollers = 0\n\n        for x in bills:\n            if x == 5:\n                five_dollers += 1\n            elif x == 10:\n                if five_dollers > 0:\n                    five_dollers -= 1\n                else:\n                    return False\n                ten_dollers += 1\n            else:\n                if five_dollers > 0 and ten_dollers > 0:\n                    five_dollers -= 1\n                    ten_dollers -= 1\n                elif five_dollers > 2 :\n                    five_dollers -= 3\n                else:\n                    return False\n            print(five_dollers, ten_dollers)\n        return True\n```\n```C++ []\nclass Solution {\npublic:\n    bool lemonadeChange(vector<int>& bills) {\n        int five_dollars = 0, ten_dollars = 0;\n        \n        for (int x : bills) {\n            if (x == 5) {\n                five_dollars++;\n            } else if (x == 10) {\n                if (five_dollars > 0) {\n                    five_dollars--;\n                    ten_dollars++;\n                } else {\n                    return false;\n                }\n            } else {\n                if (five_dollars > 0 && ten_dollars > 0) {\n                    five_dollars--;\n                    ten_dollars--;\n                } else if (five_dollars > 2) {\n                    five_dollars -= 3;\n                } else {\n                    return false;\n                }\n            }\n        }\n        \n        return true;\n    }\n};\n```\n```Java []\nclass Solution {\n    public boolean lemonadeChange(int[] bills) {\n        int five_dollars = 0, ten_dollars = 0;\n\n        for (int x : bills) {\n            if (x == 5) {\n                five_dollars++;\n            } else if (x == 10) {\n                if (five_dollars > 0) {\n                    five_dollars--;\n                    ten_dollars++;\n                } else {\n                    return false;\n                }\n            } else {\n                if (five_dollars > 0 && ten_dollars > 0) {\n                    five_dollars--;\n                    ten_dollars--;\n                } else if (five_dollars > 2) {\n                    five_dollars -= 3;\n                } else {\n                    return false;\n                }\n            }\n        }\n\n        return true;\n    }\n}\n```\n![unnamed.jpg](https://assets.leetcode.com/users/images/ad1d1146-e320-4289-8268-8d8ed8037897_1723681519.7139606.jpeg)\n
['Array', 'Greedy', 'Python', 'C++', 'Java', 'Python3']