Check string for palindrome

前端 未结 30 3664
悲哀的现实
悲哀的现实 2020-11-22 02:47

A palindrome is a word, phrase, number or other sequence of units that can be read the same way in either direction.

To check whether a word is a palindrome I get th

30条回答
  •  礼貌的吻别
    2020-11-22 03:35

    Checking palindrome for first half of the string with the rest, this case assumes removal of any white spaces.

    public int isPalindrome(String a) {
            //Remove all spaces and non alpha characters
            String ab = a.replaceAll("[^A-Za-z0-9]", "").toLowerCase();
            //System.out.println(ab);
    
            for (int i=0; i

提交回复
热议问题