Check string for palindrome

前端 未结 30 3181
悲哀的现实
悲哀的现实 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:29

    private static boolean isPalindrome(String word) {
    
            int z = word.length();
            boolean isPalindrome = false;
    
            for (int i = 0; i <= word.length() / 2; i++) {
                if (word.charAt(i) == word.charAt(--z)) {
                    isPalindrome = true;
                }
            }
    
            return isPalindrome;
        }
    

提交回复
热议问题