首页 > 其他 > 详细

848.Shifting Letters——weekly contest 87

时间:2018-06-11 01:12:08      阅读:165      评论:0      收藏:0      [点我收藏+]

848. Shifting Letters

题目链接:https://leetcode.com/problems/shifting-letters/description/

思路:O(N^2)复杂度过不了;先处理shifts, 从尾到头执行shifts[i] = sum(shifts[i+1]+...+shifts[n-1])。

注意点:会爆int,及时取余或用longlong。

 1 string shiftingLetters(string S, vector<int>& shifts) {
 2         int n = S.size();
 3         for(int i = n - 2; i >= 0 ; i--){
 4             shifts[i] += shifts[i+1];
 5             shifts[i] = shifts[i]%26;   
 6         }
 7         for(int i = 0; i < n; i++){
 8             S[i] = (S[i]-a+shifts[i])%26 + a;
 9         }
10         return S;
11     }

 

848.Shifting Letters——weekly contest 87

原文:https://www.cnblogs.com/jinjin-2018/p/9165144.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!