题解 | #判断回文# -- [Python3]

判断回文

http://www.nowcoder.com/practice/e297fdd8e9f543059b0b5f05f3a7f3b2

步骤

  1. 用Python中的list方法使字符串 列表化
  2. 用list中的reverse方法对其 翻转
  3. 判断翻转之后的 和 翻转之前两个list是否相同
  4. 相同为True,否则为FALSE
    class Solution:
     def judge(self , str ):
         # write code here
         chars = list(str)
         chars.reverse()
         charsRev = chars.copy()
         chars.reverse()
         if chars == charsRev:
             return True
         return False
    

```

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务