首页 > 试题广场 >

判断回文串

[编程题]判断回文串
  • 热度指数:110 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 256M,其他语言512M
  • 算法知识视频讲解
给定一个字符串,判断是否回文串,只考虑字母数字字符和忽略大小写。
示例1

输入

"A man, a plan, a canal: Panama"

输出

1
我这么写是不是比较麻烦
public int isParlindrome (String s) {
        // write code here
         char [] array = s.toCharArray();
            Stack stack = new Stack();
            ArrayList arrayList = new ArrayList();
            for (int i = 0; i < array.length; i++){
                stack.add(array[i]);
                arrayList.add(array[i]);
            }
            System.out.println(stack);
            System.out.println(arrayList);
            for (int i = 0; i < array.length/2; i++){
                if (stack.pop() != arrayList.remove(0)){
                    return 0;
                }
            }
            // write code here
            return 1;
    }

发表于 2023-01-19 15:03:27 回复(0)