当前位置:网站首页>2138. 将字符串拆分为若干长度为 k 的组
2138. 将字符串拆分为若干长度为 k 的组
2022-06-24 07:06:00 【拽拽就是我】
leetcode力扣刷题打卡
题目:2138. 将字符串拆分为若干长度为 k 的组
描述:字符串 s 可以按下述步骤划分为若干长度为 k 的组:
第一组由字符串中的前 k 个字符组成,第二组由接下来的 k 个字符串组成,依此类推。每个字符都能够成为 某一个 组的一部分。
对于最后一组,如果字符串剩下的字符 不足 k 个,需使用字符 fill 来补全这一组字符。
注意,在去除最后一个组的填充字符 fill(如果存在的话)并按顺序连接所有的组后,所得到的字符串应该是 s 。
给你一个字符串 s ,以及每组的长度 k 和一个用于填充的字符 fill ,按上述步骤处理之后,返回一个字符串数组,该数组表示 s 分组后 每个组的组成情况 。
解题思路
1、先补齐再拆分会好写一点;
原代码##
class Solution {
public:
vector<string> divideString(string s, int k, char fill) {
vector<string>v;
while (s.size() % k) s += fill;
int i = 0;
while (i < s.size()) {
v.push_back(s.substr(i, k));
i += k;
}
return v;
}
};
边栏推荐
- 2021-05-20computed和watch应用与区别
- Scheduled database backup script
- Base64编码详解及其变种(解决加号在URL变空格问题)
- [micro services ~nacos] Nacos service providers and service consumers
- orb slam build bug: undefined reference to symbol ‘_ ZN5boost6system15system_ categoryEv‘
- Ordering of MySQL composite index
- ZUCC_ Principles of compiling language and compilation_ Experiment 0607 grammar analysis ll analysis
- 日本大阪大学万伟伟研究员介绍基于WRS系统机器人的快速集成方法和应用
- How to mount a USB hard disk with NTFS file format under RHEL5 system
- Glusterfs replacement failure brick
猜你喜欢

Background management of uniapp hot update

成为IEEE学生会员

liunx服务器 telnet 带用户名 端口登陆方法

Centos7 installation of jdk8, mysql5.7 and Navicat connection to virtual machine MySQL and solutions (solutions to MySQL download errors are attached)

Two methods of QT exporting PDF files

【NOI模拟赛】寄(树形DP)

Jenkins自动化部署,连接不到所依赖的服务【已解决】

js中通过key查找和更新对象中指定值的方法

中国芯片独角兽公司

日本大阪大学万伟伟研究员介绍基于WRS系统机器人的快速集成方法和应用
随机推荐
Shell basic operator -- arithmetic operator
项目部署相关
leetcode 1268. Search suggestions system
一文讲透,商业智能BI未来发展趋势如何
liunx服务器 telnet 带用户名 端口登陆方法
原生小程序用画布制作海报,等比例缩放,和uniapp差不多就是写法有点不同
PHP代码加密的几种方案
Numpy 中的方法汇总
Use cpulimit to free up your CPU
Get screen width and height tool class
【力扣10天SQL入门】Day2
K8S部署高可用postgresql集群 —— 筑梦之路
第七章 操作位和位串(三)
How to replace the web player easyplayerproactivex Key in OCX?
api平台通用签名机制
小程序云数据,数据请求一个集合数据的方法
QT writing security video monitoring system 36 onvif continuous movement
Three ways to uninstall Symantec Endpoint Protection Symantec
Building a static website with eleventy
Lombok use