Kotlin OOP Solution | O(n) Time, beats 100%
Approach\n\nGreedy\n\n# Complexity\n\n- Time complexity: O(n)\n- Space complexity: O(1)\n\n# Code\n\nkt\nclass Solution {\n    fun lemonadeChange(bills: IntArra
# Approach\n\nGreedy\n\n# Complexity\n\n- Time complexity: $$O(n)$$\n- Space complexity: $$O(1)$$\n\n# Code\n\n```kt\nclass Solution {\n    fun lemonadeChange(bills: IntArray): Boolean {\n        bank.reset()\n        return bills.all { bill ->\n            bank.change(bill)\n        }\n    }\n\n    companion object {\n        private val bank = Bank()\n    }\n}\n\nprivate class Bank() {\n    private var five: Int = 0\n    private var ten: Int = 0\n\n    fun change(bill: Int): Boolean {\n        when (bill) {\n            5 -> {\n                ++this.five\n            }\n            10 -> {\n                if (this.five == 0) return false\n                --this.five\n                ++this.ten\n            }\n            20 -> {\n                if (this.ten == 0) {\n                    if (this.five < 3) return false\n                    this.five -= 3\n                } else {\n                    if (this.five == 0) return false\n                    --this.five\n                    --this.ten\n                }\n            }\n            else -> {}\n        }\n        return true\n    }\n\n    fun reset() {\n        this.five = 0\n        this.ten = 0\n    }\n}\n```\n\n# Screenshot\n\n![image.png](https://assets.leetcode.com/users/images/95230a21-324b-4077-b5db-b6481585c52e_1707786964.8372664.png)\n
['Array', 'Greedy', 'Kotlin']