1.Python 中间字符串反转解法
#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
# @param str string字符串 待判断的字符串
# @return bool布尔型
#
class Solution:
def judge(self , str ):
# write code here
if len(str)==1:
return True
if len(str)%2==0:
mid=len(str)//2
if str[0:mid]==str[mid:][::-1]:
return True
else:
mid=(len(str)-1)//2
if str[0:mid]==str[mid+1:][::-1]:
return True
return False 2.Python 整体字符串反转解法
class Solution:
def judge(self , str ):
# write code here
if not str:
return True
# 库函数
new_str = str[::-1]
return new_str == str
京公网安备 11010502036488号