题解 | 穷哈哈~

穷哈哈~

https://www.nowcoder.com/practice/5b3184b233f34fb39a7f259ae82eb42c

# -*- coding: utf-8 -*-
"""
Created on Mon Jan 12 20:30:20 2026

@author: 11924
"""
o=int(input())
s = list(input())
maxlen = 0
l,r=0,0
ha={'a':'h','h':'a'}
current=0
last=0
for i in range(len(s)):
    if current==0:
        if s[i] in ha.values():
            current+=1
            last=i
    else:
        if s[i] == ha[s[last]]:
            current+=1
            last=i
        else:
            maxlen=max(maxlen,current)
            if s[i]in ha.values():
                current=1
            else:
                current=0
   # print(f"i:{i}  s[i]:{s[i]}      last:{last}     maxlen:{maxlen}     cur:{current}")
    maxlen=max(maxlen,current)
print(maxlen)

在不匹配时,cur不可以直接置0

全部评论

相关推荐

递归到脑子变傻:杭州还有上位机用VB的,实在没绷住
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务