Greedily spend 5 dollar change | Java | C++
Intuition, approach, and complexity dicussed in video solution in detail\nhttps://youtu.be/p_jI8P-AKP8\n# Code\nJava\n\nclass Solution {\n    public boolean lem
# Intuition, approach, and complexity dicussed in video solution in detail\nhttps://youtu.be/p_jI8P-AKP8\n# Code\nJava\n```\nclass Solution {\n    public boolean lemonadeChange(int[] bills) {\n        int fiveCnt = 0, tenCnt = 0;\n        for(var bill : bills){\n            if(bill == 5)fiveCnt++;\n            else if(bill == 10){\n                if(fiveCnt == 0)return false;\n                else fiveCnt--;\n                tenCnt++;\n            }else{\n                if(fiveCnt == 0 || (fiveCnt < 3 && tenCnt == 0))return false;\n                else{\n                    if(tenCnt == 0)fiveCnt -= 3;\n                    else{\n                        fiveCnt--;\n                        tenCnt--;\n                    }\n                }\n            }\n            \n        }\n        return true;\n    }\n}\n```\nC++\n```\nclass Solution {\npublic:\n    bool lemonadeChange(vector<int>& bills) {\n        int fiveCnt = 0, tenCnt = 0;\n        for(auto bill : bills){\n            if(bill == 5)fiveCnt++;\n            else if(bill == 10){\n                if(fiveCnt == 0)return false;\n                else fiveCnt--;\n                tenCnt++;\n            }else{\n                if(fiveCnt == 0 || (fiveCnt < 3 && tenCnt == 0))return false;\n                else{\n                    if(tenCnt == 0)fiveCnt -= 3;\n                    else{\n                        fiveCnt--;\n                        tenCnt--;\n                    }\n                }\n            }\n            \n        }\n        return true;\n    }\n};\n```
['Array', 'Greedy', 'C++', 'Java']