Palindrome Partitioning I , II , III   |  java clean solution
Palindrome partitioning I\n\n\n public List<List<String>> partition(String s) {\n        List<List<String>> res = new ArrayList<>();\n        boolean[][] dp = n
## Palindrome partitioning I\n\n```\n public List<List<String>> partition(String s) {\n        List<List<String>> res = new ArrayList<>();\n        boolean[][] dp = new boolean[s.length()][s.length()];\n        for(int i = 0; i < s.length(); i++) {\n            for(int j = 0; j <= i; j++) {\n                if(s.charAt(i) == s.charAt(j) && (i - j <= 2 || dp[j+1][i-1])) {\n                    dp[j][i] = true;\n                }\n            }\n        }\n        helper(res, new ArrayList<>(), dp, s, 0);\n        return res;\n    }\n    \n    private void helper(List<List<String>> res, List<String> path, boolean[][] dp, String s, int pos) {\n        if(pos == s.length()) {\n            res.add(new ArrayList<>(path));\n            return;\n        }\n        \n        for(int i = pos; i < s.length(); i++) {\n            if(dp[pos][i]) {\n                path.add(s.substring(pos,i+1));\n                helper(res, path, dp, s, i+1);\n                path.remove(path.size()-1);\n            }\n        }\n    }\n\n\n```\n## Palindrome partitioning II\n\n```\npublic int minCut(String s) {\n        int n=s.length();\n        int[] dp=new int[n];\n        boolean[][] isP=new boolean[n][n];\n        for(int i=0;i<n;i++){\n            int min=i;\n            for(int j=0;j<=i;j++)\n                if(s.charAt(i)==s.charAt(j) && (i-j<2 || isP[j+1][i-1])){\n                    isP[j][i]=true;\n                    min= j==0 ? 0 : Math.min(min,dp[j-1]+1);\n                }\n            dp[i]=min;\n        }\n   \n        return dp[n-1];   \n    }\n\n```\n## Palindrome partitioning III\n```\nclass Solution {\n    public int palindromePartition(String s, int K) {\n        int n=s.length();\n        int[][] min_changes=new int[n+1][n+1];\n        int[][] dp=new int[n+1][K+1];\n\n        for(int[] i:dp) Arrays.fill(i,Integer.MAX_VALUE);\n\n        dp[0][0]=0;\n\n        for(int i=1;i<=n;i++){\n            for(int k=1;k<=K;k++){\n                for(int j=1;j<=i;j++){\n                    int changes= s.charAt(j-1)==s.charAt(i-1) ? 0:1;\n\n                    changes+=i-j<=1 ? 0: min_changes[j+1][i-1];\n                    if(dp[j-1][k-1]!=Integer.MAX_VALUE)\n                        dp[i][k]=Math.min(dp[i][k], dp[j-1][k-1]+changes);\n                    min_changes[j][i]= changes;\n                }\n            }\n        }\n        return dp[n][K];\n    }\n}\n```
['Java']