Check string for palindrome

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

    Recently I wrote a palindrome program which doesn't use StringBuilder. A late answer but this might come in handy to some people.

    public boolean isPalindrome(String value) {
        boolean isPalindrome = true;
        for (int i = 0 , j = value.length() - 1 ; i < j ; i ++ , j --) {
            if (value.charAt(i) != value.charAt(j)) {
                isPalindrome = false;
            }
        }
        return isPalindrome;
    }
    

提交回复
热议问题