Check string for palindrome

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

    Amazing how many different solutions to such a simple problem exist! Here's another one.

    private static boolean palindrome(String s){
        String revS = "";
        String checkS = s.toLowerCase();
        String[] checkSArr = checkS.split("");
    
        for(String e : checkSArr){
            revS = e + revS;
        }
    
        return (checkS.equals(revS)) ? true : false;
    }
    

提交回复
热议问题