Java detects whether the string is a palindrome string

From , 3 Years ago, written in Java, viewed 51 times.
URL https://pastebin.vip/view/e4191d61
  1. /**检测回文串:
  2.      * 先判断该字符的第一个和最后一个字符是否相等。如果相等,检查第二个字符和倒数第二个字符
  3.      * 是否相等。这个过程继续进行,直到出现不配陪的情况或者字符串的所有字符都检验完了。当字
  4.      * 符串有奇数个字符时,不用检查中间字符。
  5.      * @param s
  6.      * @return
  7.      */  
  8.     public static boolean isPalindrome(String s){  
  9.         int low = 0;  
  10.         int high = s.length()-1;  
  11.         //当字符串有奇数个字符时,不用检查中间字符  
  12.         while(low < high){  
  13.             if(s.charAt(low)!=s.charAt(high)){  
  14.                 return false;  
  15.             }  
  16.             low ++;  
  17.             high --;  
  18.         }  
  19.         return true;  
  20.     }  
  21. //java/7220

Reply to "Java detects whether the string is a palindrome string"

Here you can reply to the paste above

captcha

https://burned.cc - Burn After Reading Website