C++ - Easy beats 100% of solutions [0 ms]
There are only 5 possible ways of adding brackets to an expression of length 4.\n\nLets\' say the expression nums = { a , b, c , d}. The only possible sequence 
There are only 5 possible ways of adding brackets to an expression of length 4.\n\nLets\' say the expression nums = { a , b, c , d}. The only possible sequence of brackets is:\nHere **op** represent any operation in the set { + , - , / , * }\n1. (a op1 b) op2 (c op3 d)\n2. ((a op1 b) op2 c) op3 d\n3. a op1 (b op2 c) op3 d\n4. a op1 ((b op2 c) op3 d)\n5. a op1 (b op2 (c op3 d))\n\nFor every possible sequence of brackets (from above mentioned 5), we need to choose the values, op1, op2 and op3. Each of which belongs to set { +, -, /, * }.\nTherefore, Possibilities for each possible sequence = 4 * 4 * 4 = 64\nWe have 5 possible sequences, there total possibilities  = 5 * 64 = 320\n\nNow, we have 320 possible outputs for one nums sequence of the form {a, b, c, d}.\n\nIn the given question, it is also mentioned that we can choose the given numbers in any possible combination. Therefore, we have to consider all possible permutations:\nFor eg: Given nums = {1,3,4,6} \nWe can also use numbers in a different order like 6 / ( 1 - 3 / 4 ).\n\nSince the sequence is of size 4, there can be 24 possible permutations.\nTherefore total possibilites = 24 * 320 = 7680\n\n\n```\n\n\nclass Solution {\npublic:\n    \n    char ops[4] = {\'*\',\'/\',\'+\',\'-\'};\n    vector<string> poss;\n    const double INF = 1e-9;\n    \n    double process(double num1, double num2, char sym) {\n        switch (sym) {\n            case \'+\':\n                return num1+num2;\n            case \'-\':\n                return num1-num2;\n            case \'*\':\n                return num1*num2;\n            case \'/\':\n                return num1/num2;\n        }\n        \n        return 0;\n    }\n    \n    bool way1(vector<vector<int>>& numss) {\n        double temp1, temp2, temp3;\n        for (auto nums: numss) {\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                        \n                        // Way1 --> (nums[0] opI nums[1]) opJ (num[2] opK nums[3])\n                        \n                        temp1 = process(nums[0], nums[1], ops[i]);\n                        temp2 = process(nums[2], nums[3], ops[j]);\n                        temp3 = process(temp1, temp2, ops[k]);\n                        //cout<<"way1 --"<<ops[i]<<" "<<ops[j]<<" "<<ops[k]<<" "<<temp1<<" "<<temp2<<" "<<temp3<<"\\n";\n                        if (fabs(24-temp3) < INF)\n                            return true;\n                    }\n                }\n            }\n        }\n        return false;\n    }\n    \n    bool way2(vector<vector<int>>& numss) {\n        double temp1, temp2, temp3;\n        for (auto nums: numss) {\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                        \n                        // Way2 --> ((nums[0] opI nums[1]) opJ num[2]) opK nums[3]\n                        \n                        temp1 = process(nums[0], nums[1], ops[i]);\n                        temp2 = process(temp1, nums[2], ops[j]);\n                        temp3 = process(temp2, nums[3], ops[k]);\n                        if (fabs(24-temp3) < INF)\n                            return true;\n                    }\n                }\n            }\n        }\n        return false;\n    }\n    \n    bool way3(vector<vector<int>>& numss) {\n        double temp1, temp2, temp3;\n        for (auto nums: numss) {\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                        \n                        // Way3 --> nums[0] opJ (nums[1] opI num[2]) opK nums[3]\n                        \n                        temp1 = process(nums[1], nums[2], ops[i]);\n                        temp2 = process(nums[0], temp1, ops[j]);\n                        temp3 = process(temp2, nums[3], ops[k]);\n                        if (fabs(24-temp3) < INF)\n                            return true;\n                    }\n                }\n            }\n        }\n        return false;\n    }\n    \n    bool way4(vector<vector<int>>& numss) {\n        double temp1, temp2, temp3;\n        for (auto nums: numss) {\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                        \n                        // Way4 --> nums[0] opK ((nums[1] opI num[2]) opJ nums[3])\n                        \n                        temp1 = process(nums[1], nums[2], ops[i]);\n                        temp2 = process(temp1, nums[3], ops[j]);\n                        temp3 = process(nums[0], temp2, ops[k]);\n                        if (fabs(24-temp3) < INF)\n                            return true;\n                    }\n                }\n            }\n        }\n        return false;\n    }\n    \n    bool way5(vector<vector<int>>& numss) {\n        double temp1, temp2, temp3;\n        for (auto nums: numss) {\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                        \n                         // Way5 --> nums[0] opK (nums[1] opJ (num[2] opI nums[3]))\n                        \n                        temp1 = process(nums[2], nums[3], ops[i]);\n                        temp2 = process(nums[1], temp1, ops[j]);\n                        temp3 = process(nums[0], temp2, ops[k]);\n                        if (fabs(24-temp3) < INF)\n                            return true;\n                    }\n                }\n            }\n        }\n        return false;\n    }\n    \n    bool judgePoint24(vector<int>& nums) {\n        \n        vector<vector<int>> numss;\n        sort(nums.begin(), nums.end());\n        do {\n            numss.push_back(nums);\n            \n        } while (next_permutation(nums.begin(), nums.end()));\n        \n        return way1(numss) || way2(numss) || way3(numss) || way4(numss) || way5(numss);\n    }\n};\n```
[]