当前位置:网站首页>1844. 将所有数字用字符替换
1844. 将所有数字用字符替换
2022-06-24 07:06:00 【拽拽就是我】
leetcode力扣刷题打卡
1844. 将所有数字用字符替换
描述:给你一个下标从 0 开始的字符串 s ,它的 偶数 下标处为小写英文字母,奇数 下标处为数字。
定义一个函数 shift(c, x) ,其中 c 是一个字符且 x 是一个数字,函数返回字母表中 c 后面第 x 个字符。
比方说,shift(‘a’, 5) = ‘f’ 和 shift(‘x’, 0) = ‘x’ 。
对于每个 奇数 下标 i ,你需要将数字 s[i] 用 shift(s[i-1], s[i]) 替换。
请你替换所有数字以后,将字符串 s 返回。题目 保证 shift(s[i-1], s[i]) 不会超过 ‘z’ 。
解题思路
1、题目看着复杂,实则水的一逼。
原代码##
class Solution {
public:
string replaceDigits(string s) {
for (int i = 0; i < s.size(); ++i) {
if (i % 2 == 1) {
s[i] = s[i - 1] + s[i] - '0';
}
}
return s;
}
};
边栏推荐
猜你喜欢

Detailed explanation of Base64 coding and its variants (to solve the problem that the plus sign changes into a space in the URL)

input的聚焦后的边框问题

日本大阪大学万伟伟研究员介绍基于WRS系统机器人的快速集成方法和应用

關於ETL看這篇文章就够了,三分鐘讓你明白什麼是ETL

【关于运维和网工的差别,一文说透】

rpiplay实现树莓派AirPlay投屏器

ZUCC_编译语言原理与编译_实验06 07 语法分析 LL 分析

MySQL 因字符集问题插入中文数据时提示代码 :1366

疫情、失业,2022,我们高喊着摆烂和躺平!

New technology practice, encapsulating the permission application library step by step with the activity results API
随机推荐
【力扣10天SQL入门】Day3
Lombok use
xtrabackup做数据备份
Shell basic operator -- arithmetic operator
分布式 | 如何与 DBLE 进行“秘密通话”
input的聚焦后的边框问题
Building a static website with eleventy
图片工具
pymysql 向MySQL 插入数据无故报错
一文详解|增长那些事儿
RuntimeError: Missing dependencies:XXX
Common misconceptions in Tencent conference API - signature error_ code 200003
Get screen width and height tool class
小程序云数据,数据请求一个集合数据的方法
疫情、失业,2022,我们高喊着摆烂和躺平!
深度学习与神经网络:最值得关注的6大趋势
Summary of methods in numpy
Live broadcast appointment: growth of Mengxin Product Manager
Rust procedure macro simply imitates Lombok function
Tencent cloud ASR product PHP realizes real-time voice authentication request