(C++) 679. 24 Game
\n\nclass Solution {\npublic:\n    bool judgePoint24(vector<int>& cards) {\n        \n        function<bool(vector<double>&)> fn = [&] (vector<double>& nums) {\
\n```\nclass Solution {\npublic:\n    bool judgePoint24(vector<int>& cards) {\n        \n        function<bool(vector<double>&)> fn = [&] (vector<double>& nums) {\n            if (nums.size() == 1) return abs(nums[0] - 24) < 1e-6; \n            for (int i = 0; i < nums.size(); ++i) {\n                for (int j = i+1; j < nums.size(); ++j) {\n                    vector<double> cand; \n                    for (int k = 0; k < nums.size(); ++k) \n                        if (k != i && k != j) cand.push_back(nums[k]); \n                    vector<double> vals = {nums[i]+nums[j], nums[i]-nums[j], nums[j]-nums[i], nums[i]*nums[j]}; \n                    if (nums[j]) vals.push_back(nums[i]/nums[j]); \n                    if (nums[i]) vals.push_back(nums[j]/nums[i]); \n                    for (auto& x : vals) {\n                        cand.push_back(x); \n                        if (fn(cand)) return true; \n                        cand.pop_back(); \n                    }\n                }\n            }\n            return false; \n        }; \n        \n        vector<double> nums(cards.begin(), cards.end()); \n        return fn(nums); \n        \n    }\n};\n```
['C']