JAVA | 2 approaches - same logic | Dirty + Clean codes
Please Upvote :D\n##### 1. Messed up approach:\n\nclass Solution {\n    public int countTime(String time) {\n        char[] Time = time.toCharArray();\n\n      
### **Please Upvote** :D\n##### 1. Messed up approach:\n```\nclass Solution {\n    public int countTime(String time) {\n        char[] Time = time.toCharArray();\n\n        int hrs = 1;\n\n        if (Time[0] == \'?\' && Time[1] == \'?\') {\n            hrs = 24;\n        }\n        else if (Time[0] == \'?\' && Time[1] != \'?\') {\n            if (Time[1] > \'3\') hrs = 2;\n            else hrs = 3;\n        }\n        else if (Time[0] != \'?\' && Time[1] == \'?\') {\n            if (Time[0] == \'2\') hrs = 4;\n            else hrs = 10;\n        }\n\n        int mins = 1;\n\n        if (Time[3] == \'?\' && Time[4] == \'?\') {\n            mins *= 60;\n        }\n        else if (Time[3] == \'?\' && Time[4] != \'?\') {\n            mins *= 6;\n        }\n        else if (Time[3] != \'?\' && Time[4] == \'?\') {\n            mins *= 10;\n        }\n\n        return hrs * mins;\n    }\n}\n```\n##### 2. Cleaner approach from calm mind:\n```\nclass Solution {\n    public int countTime(String time) {\n        if (time.equals("??:??")) return 24 * 60;\n\n        char[] t = time.toCharArray();\n        int ans = 1;\n\n        if (t[0] == \'?\' && t[1] == \'?\') ans *= 24;\n\n        else if (t[0] == \'?\') {\n            ans *= (t[1] > \'3\') ? 2 : 3;\n        }\n\n        else if (t[1] == \'?\') {\n            ans *= (t[0] == \'2\') ? 4 : 10;\n        }\n\n        if (t[3] == \'?\') ans *= 6;\n        if (t[4] == \'?\') ans *= 10;\n\n        return ans;\n    }\n}\n\n\n// TC: O(1), SC: O(n)\n```
['Java']