题解 | #穷哈哈~#

穷哈哈~

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

简单的状态转移

n=int(input())
s=input()
dp=[0]*n
for i in range(0,n):
    if(i>0 and s[i-1]=='a' and s[i]=='h'):
        dp[i]=dp[i-1]+1
    elif(i>0 and s[i-1]=='h' and s[i]=='a'):
        dp[i]=dp[i-1]+1
    elif(s[i]=='a' or s[i]=='h'):
        dp[i]=1
print(max(dp))
全部评论

相关推荐

好羡慕走AI技术方向的人,实习薪资这么高😱 人比人气死人😭
勇敢的嘟教授在考古:芯片公司挣得多多的,钱给的还不如互联网
点赞 评论 收藏
分享
再懒也要睡懒觉:大学4年玩的挺爽的哈😅
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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