Leetcode 9 回文数

题目

代码分析

简单的递归

代码展示

public static boolean isPalindrome(int x) {
        String temp=String.valueOf(x);
        if(temp.charAt(0)=='-') return false;
        return f(temp.toCharArray(),0,temp.length()-1);
    }
    public static boolean f(char[] chas,int start,int end)
    {
        if(start==end) return true;
        else if(start==end-1) return chas[start]==chas[end];
        else if(chas[start]==chas[end])
            return f(chas,start+1,end+1);
        return false;
    }

学习情况

1次

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务