左右指针回文

 public static boolean isLooped(int num) {
        StringBuilder strBuilder = new StringBuilder(String.valueOf(num));
        int l = 0; //左指针
        int r = strBuilder.length() - 1; //右指针
        while (l < r) {
            if (strBuilder.charAt(l) != strBuilder.charAt(r)) {
                return false;
            }
            ++l;
            --r;
        }
        return true;
    }

 

posted @ 2021-07-09 13:38  活出自己范儿  Views(40)  Comments(0Edit  收藏  举报