[C++/Java/Python] Straight Forward
Intuition:\nWhen the customer gives us $20, we have two options:\n1. To give three $5 in return\n2. To give one $5 and one $10.\n\nOn insight is that the second
## **Intuition**:\nWhen the customer gives us `$20`, we have two options:\n1. To give three `$5` in return\n2. To give one `$5` and one `$10`.\n\nOn insight is that the second option (if possible) is always better than the first one.\nBecause two `$5` in hand is always better than one `$10`\n<br>\n\n## **Explanation**:\nCount the number of `$5` and `$10` in hand.\n\nif (customer pays with `$5`) `five++`;\nif (customer pays with `$10`) `ten++, five--`;\nif (customer pays with `$20`) `ten--, five--` or `five -= 3`;\n\nCheck if five is positive, otherwise return false.\n<br>\n\n## **Time Complexity**\nTime `O(N)` for one iteration\nSpace `O(1)`\n<br>\n\n**C++:**\n```cpp\n    int lemonadeChange(vector<int> bills) {\n        int five = 0, ten = 0;\n        for (int i : bills) {\n            if (i == 5) five++;\n            else if (i == 10) five--, ten++;\n            else if (ten > 0) ten--, five--;\n            else five -= 3;\n            if (five < 0) return false;\n        }\n        return true;\n    }\n```\n\n**Java:**\n```java\n    public boolean lemonadeChange(int[] bills) {\n        int five = 0, ten = 0;\n        for (int i : bills) {\n            if (i == 5) five++;\n            else if (i == 10) {five--; ten++;}\n            else if (ten > 0) {ten--; five--;}\n            else five -= 3;\n            if (five < 0) return false;\n        }\n        return true;\n    }\n```\n**Python:**\n```py\n    def lemonadeChange(self, bills):\n        five = ten = 0\n        for i in bills:\n            if i == 5: five += 1\n            elif i == 10: five, ten = five - 1, ten + 1\n            elif ten > 0: five, ten = five - 1, ten - 1\n            else: five -= 3\n            if five < 0: return False\n        return True\n```\n
[]