Java solution building closest palindrome
Inspired by 564. Find the Closest Palindrome\n\n\nclass Solution {\n    public int primePalindrome(int N) {\n        while (N < Integer.MAX_VALUE) {\n          
Inspired by [564. Find the Closest Palindrome](https://leetcode.com/problems/find-the-closest-palindrome/description/)\n\n```\nclass Solution {\n    public int primePalindrome(int N) {\n        while (N < Integer.MAX_VALUE) {\n            N = nextPalin("" + N);\n            if (isPrime(N)) {\n                return N;\n            }\n            N++;\n        }\n        return -1;\n    }\n    private int nextPalin(String n) {\n        int l = n.length();\n        List<Integer> cands = new LinkedList<>();\n        int half = Integer.valueOf(n.substring(0, (l + 1) / 2));\n        for (int i = half; i <= half + 1; i++) {\n            String halfString = "" + i;\n            if (l % 2 == 1) {\n                halfString = halfString.substring(0, halfString.length() - 1);\n            }\n            String newString = "" + i + new StringBuilder(halfString).reverse().toString();\n            cands.add(Integer.valueOf(newString));\n        }\n        int ori = Integer.valueOf(n), result = Integer.MAX_VALUE;\n        for (int cand : cands) {\n            if (cand >= ori && cand < result) {\n                result = cand;\n            }\n        }\n        return result;\n    }\n    private boolean isPrime(int n) {\n        if (n <= 1) {\n            return false;\n        }\n        long l = (long)n;\n        for (long i = 2; i * i <= l; i++) {\n            if (l % i == 0) {\n                return false;\n            }\n        }\n        return true;\n    }\n}\n```
[]