当前位置:网站首页>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;
}
};
边栏推荐
- 何时使用RDD和DataFrame/DataSet
- Mysql数据(Liunx环境)定时备份
- 【生活思考】计划与自律
- Glusterfs replacement failure brick
- Live broadcast appointment: growth of Mengxin Product Manager
- How to replace the web player easyplayerproactivex Key in OCX?
- À propos de ETL il suffit de lire cet article, trois minutes pour vous faire comprendre ce qu'est ETL
- Three ways to uninstall Symantec Endpoint Protection Symantec
- 数据中台:数据中台全栈技术架构解析,附带行业解决方案
- uniapp 热更新后台管理
猜你喜欢

K8S部署高可用postgresql集群 —— 筑梦之路

New technology practice, encapsulating the permission application library step by step with the activity results API

Centos7安装jdk8以及mysql5.7以及Navicat连接虚拟机mysql的出错以及解决方法(附mysql下载出错解决办法)

关于ETL看这篇文章就够了,三分钟让你明白什么是ETL

WebRTC系列-网络传输之5选择最优connection切换

MATLAB Camera Calibrator相机标定

Redis的Cluster集群数据倾斜

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

数据库迁移从PostgreSQL迁移到 MYSQL

【NOI模拟赛】给国与时光鸡(构造)
随机推荐
There was an error checking the latest version of pip
利用sonar做代码检查
PHP代码加密的几种方案
Three ways to uninstall Symantec Endpoint Protection Symantec
深度学习与神经网络:最值得关注的6大趋势
Common date formatter and QT method for obtaining current time
Redis cluster data skew
Base64编码详解及其变种(解决加号在URL变空格问题)
饼状统计图,带有标注线,都可以自行设定其多种参数选项
The pie chart with dimension lines can set various parameter options
QT source code analysis -- QObject (2)
Variable declaration and some special variables in shell
第七章 操作位和位串(三)
How to improve the customer retention rate in the operation of independent stations? Customer segmentation is very important!
leetcode 1642. Furthest building you can reach
QT writing security video monitoring system 36 onvif continuous movement
Redis的Cluster集群数据倾斜
There was an error checking the latest version of pip
何时使用RDD和DataFrame/DataSet
2022.06.23(LC_144,94,145_二叉树的前序、中序、后序遍历)