目录
判断一个字符串是否为回文字符串
访问量:1153

一、非递归

func isPalindrome(s string)bool{
   left :=0
   right :=len(s)-1
   for left<right{
      if s[left]!=s[right]{
         return false
      }
      left++
      right--
   }
   return true
}

二、递归

func isPalindrome(s string)bool  {
   strLen := len(s)
   if strLen == 1 {
      return true
   } else if strLen == 2 {
      return s[0] == s[1]
   } else {
      return isPalindrome(s[1:strLen -1]) && s[0] == s[strLen -1]
   }
}