848. Shifting Letters

问题描述:

问题规约为:对每一个数组S,移动(shifts[0] + shitfs[1]+...+shitfs[i] )mod 26位

def shiftingLetters(self, S: str, shifts: List[int]) -> str:
        #a 97  ord: char->int   chr: int->char
        sm = sum(shifts)
            
        ans = ''
        for i in range(len(S)):
            ans += chr( (ord(S[i]) - 97 + sm) % 26  + 97)
            sm -= shifts[i]
        return ans

1.把复杂问题说简单的能力
2.构建数学模型的能力

原文地址:https://www.cnblogs.com/whyaza/p/11201553.html