最长回文子串 | HJ32 密码截取
while True: try: s = input() n = 0 for i in range(len(s)): # 左右各增加一个长度,若符合回文,记录最长回文长度n if i-n-1>=0 and s[i-n-1:i+1]==s[i-n-1:i+1][::-1]: n += 2 # 仅右侧增加一个长度,若符合回文,记录最长回文长度n elif s[i-n:i+1] == s[i-n:i+1][::-1]: n += 1 print(n) except: break
用时:20min
华为笔试刷题 文章被收录于专栏
高质量题: 1~40:HJ16,HJ22,HJ24,HJ26,HJ27,HJ28,HJ35,HJ37,HJ39; 40~80:HJ41,HJ42,HJ43,HJ44,HJ48,HJ50,HJ52,HJ53,HJ57,HJ61,HJ63,HJ64,HJ70,HJ71,HJ74,HJ77; 80~108:HJ82,HJ85,HJ88,HJ89,HJ93,HJ95,HJ98,HJ103,HJ107