# 2396. Strictly Palindromic Number ###### tags: `Leetcode` `Medium` `Math` Link: https://leetcode.com/problems/strictly-palindromic-number/description/ ## 思路 暴力解就是用所有2到n-2的数字表示n 然后check它是不是palindrome 更炫酷的方法是参考[这里](https://leetcode.com/problems/strictly-palindromic-number/solutions/2524702/return-false/) 当base是n-2的时候 对于所有n>=4 n=12 ((n-2)+2) ## Code ### Brute Force ```java= class Solution { public boolean isStrictlyPalindromic(int n) { for(int i=2; i<n-1; i++){ if(!checkPalin(Integer.toString(n, i))){ return false; } } return true; } public boolean checkPalin(String s){ int p1=0, p2=s.length()-1; while(p1<p2){ if(s.charAt(p1)!=s.charAt(p2)) return false; p1++; p2--; } return true; } } ``` ### 炫酷方法 ```java= class Solution { public boolean isStrictlyPalindromic(int n) { return false; } } ```