C++ iteration based
Iterate every permutation and expression tree forms.\n\n\nclass Solution {\npublic:\n    double eval(double a, double b, int op) {\n        switch (op) {\n     
Iterate every permutation and expression tree forms.\n\n```\nclass Solution {\npublic:\n    double eval(double a, double b, int op) {\n        switch (op) {\n            case 0: return a + b;\n            case 1: return a - b;\n            case 2: return a * b;\n            case 3: return a / b;\n        }\n        return 0;\n    }\n    \n    bool is24(double x) { return abs(x - 24.0) < 1e-6; }\n    \n    bool judgePoint24(vector<int>& cards) {\n        sort(cards.begin(), cards.end());\n        do {\n            \n            for (int i = 0; i < 4; i ++)\n                for (int j = 0; j < 4; j ++)\n                    for (int k = 0; k < 4; k ++) {\n                        double a = cards[0], b = cards[1],\n                               c = cards[2], d = cards[3];\n                        \n                        // (((a b) c) d)\n                        double ans = eval(eval(eval(a, b, i), c, j), d, k);\n                        if (is24(ans))\n                            return true;\n                        // ((a b) (c d))\n                        ans = eval(eval(a, b, i), eval(c, d, k), j);\n                        if (is24(ans))\n                            return true;\n                        // (a (b (c d)))\n                        ans = eval(a, eval(b, eval(c, d, k), j), i);\n                        if (is24(ans))\n                            return true;\n                        // ((a (b c)) d)\n                        ans = eval(eval(a, eval(b, c, j), i), d, k);\n                        if (is24(ans))\n                            return true;\n                        // (a ((b c) d)))\n                        ans = eval(a, eval(eval(b, c, j), d, k), i);\n                        if (is24(ans))\n                            return true;\n                    }\n            \n        } while (next_permutation(cards.begin(), cards.end()));\n        \n        return false;\n    }\n};\n```
[]