24 Game DFS
\n\n# Code\n\nclass Solution {\n    private final char[] ops = {\'+\', \'-\', \'*\', \'/\'};\n\n    public boolean judgePoint24(int[] cards) {\n        List<Dou
\n\n# Code\n```\nclass Solution {\n    private final char[] ops = {\'+\', \'-\', \'*\', \'/\'};\n\n    public boolean judgePoint24(int[] cards) {\n        List<Double> nums = new ArrayList<>();\n        for (int num : cards) {\n            nums.add((double) num);\n        }\n        return dfs(nums);\n    }\n\n    private boolean dfs(List<Double> nums) {\n        int n = nums.size();\n        if (n == 1) {\n            return Math.abs(nums.get(0) - 24) < 1e-6;\n        }\n        boolean ok = false;\n        for (int i = 0; i < n; ++i) {\n            for (int j = 0; j < n; ++j) {\n                if (i != j) {\n                    List<Double> nxt = new ArrayList<>();\n                    for (int k = 0; k < n; ++k) {\n                        if (k != i && k != j) {\n                            nxt.add(nums.get(k));\n                        }\n                    }\n                    for (char op : ops) {\n                        switch (op) {\n                            case \'/\' -> {\n                                if (nums.get(j) == 0) {\n                                    continue;\n                                }\n                                nxt.add(nums.get(i) / nums.get(j));\n                            }\n                            case \'*\' -> {\n                                nxt.add(nums.get(i) * nums.get(j));\n                            }\n                            case \'+\' -> {\n                                nxt.add(nums.get(i) + nums.get(j));\n                            }\n                            case \'-\' -> {\n                                nxt.add(nums.get(i) - nums.get(j));\n                            }\n                        }\n                        ok |= dfs(nxt);\n                        if (ok) {\n                            return true;\n                        }\n                        nxt.remove(nxt.size() - 1);\n                    }\n                }\n            }\n        }\n        return ok;\n    }\n}\n```
['Java']