首页 > 数据库 >[Oracle] LeetCode 848. Shifting Letters

[Oracle] LeetCode 848. Shifting Letters

时间:2022-08-19 15:58:07浏览次数:67  
标签:Letters string int shift pref shifts Shifting Oracle letters

You are given a string s of lowercase English letters and an integer array shifts of the same length.

Call the shift() of a letter, the next letter in the alphabet, (wrapping around so that 'z' becomes 'a').

For example, shift('a') = 'b', shift('t') = 'u', and shift('z') = 'a'.
Now for each shifts[i] = x, we want to shift the first i + 1 letters of s, x times.

Return the final string after all such shifts to s are applied.

Solution

使用后缀数组即可。对于第 \(i\) 个位置的字符,偏移之后则为:

\[a+(s[i]-a+pref[i])\%26 \]

点击查看代码
class Solution {
private:
    string ans="";
    long long pref[100002];
    
public:
    string shiftingLetters(string s, vector<int>& shifts) {
        int n = shifts.size();
        
        for(int i=n-1;i>=0;i--){
            pref[i] = shifts[i]+pref[i+1];
        }
        for(int i=0;i<n;i++){
            ans+= (char)('a'+ (s[i]-'a'+pref[i])%26);
        }
        return ans;
    }
};

标签:Letters,string,int,shift,pref,shifts,Shifting,Oracle,letters
From: https://www.cnblogs.com/xinyu04/p/16600691.html

相关文章

  • Oracle 解决【ORA-01704:字符串文字太长】
    错误提示:oracle在toad中执行一段sql语句时,出现错误‘ORA-01704:字符串文字太长’。如下图:原因:一般为包含有对CLOB字段的数据操作。如果CLOB字段的内容非常大的时候,会导致S......
  • Dockers安装Oracle 11g
    1,下载Oracle镜像dockerpullregistry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g 2,启动容器dockerrun-d-p1521:1521--nameoracleregistry.cn-hangzh......
  • 40.Oracle的统计信息
    1.什么是统计信息统计信息主要是描述数据库中表,索引的大小,规模,数据分布状况等的一类信息。比如,表的行数,块数,平均每行的大小,索引的leafblocks,索引字段的行数,不同值的大小......
  • [Oracle] LeetCode 1740 Find Distance in a Binary Tree
    Giventherootofabinarytreeandtwointegerspandq,returnthedistancebetweenthenodesofvaluepandvalueqinthetree.Thedistancebetweentwono......
  • [Oracle] LeetCode 253 Meeting Rooms II
    Givenanarrayofmeetingtimeintervalsintervalswhereintervals[i]=[starti,endi],returntheminimumnumberofconferenceroomsrequired.Solution先按照......
  • [Oracle] LeetCode 333 Largest BST Subtree
    Giventherootofabinarytree,findthelargestsubtree,whichisalsoaBinarySearchTree(BST),wherethelargestmeanssubtreehasthelargestnumberof......
  • oracle
                       ......
  • Oracle数据库安装时,安装报错ins_emagent.mk
    安装oracle数据库过程中,通过图形界面安装,出现ins_emagent.mk报错提示  解决方法修改$ORACLE_HOME/sysman/lib/ins_emagent.mk,将$(MK_EMAGENT_NMECTL),修改为:$(MK_EMA......
  • oracle安装调用图形化失败
    报错现象:[grid@19c01grid]$./gridSetup.shERROR:Unabletoverifythegraphicaldisplaysetup.ThisapplicationrequiresXdisplay.Makesurethatxdpyinfoe......
  • Oracle:初次登陆的操作及错误处理
    1登录前准备因网络环境变更导致的监听启动报错关注虚拟机用的是桥接网络物理机使用的网络环境,有线无线编辑-虚拟机编辑器此时需要修改etc/hosts文件2登录oracleo......