3335. 字符串轉換后的長度 I
class Solution:def lengthAfterTransformations(self, s: str, t: int) -> int:# 大質數mod = 10**9+7# 創建一個長度為26的數組cnt,對應26個小寫字母cnt = [0]*26# 計算出s中26個字符分別有多少個for ch in s:cnt[ord(ch)-ord('a')] +=1for round in range(t):nxt = [0]*26# a的個數nxt[0] = cnt[25]# b的個數nxt[1] = (cnt[25] + cnt[0]) % mod# 其他字符for i in range(2,26):nxt[i] = cnt[i-1]cnt = nxtans = sum(cnt)%modreturn ans