当前位置:网站首页>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;
}
};
边栏推荐
- 【关于运维和网工的差别,一文说透】
- 一文详解|增长那些事儿
- 为什么ping不通,而traceroute却可以通
- Common CVM transcribes audio using virtual sound card
- 等保备案是什么意思?应该去哪里办理备案?
- Common misconceptions in Tencent conference API - signature error_ code 200003
- liunx 更改 vsftpd 的端口号
- JS to get the last element of the array
- 成为IEEE学生会员
- 日本大阪大学万伟伟研究员介绍基于WRS系统机器人的快速集成方法和应用
猜你喜欢

How to improve the customer retention rate in the operation of independent stations? Customer segmentation is very important!

uniapp 热更新后台管理

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

ZUCC_ Principles of compiling language and compilation_ Experiment 0607 grammar analysis ll analysis

5 minutes, excellent customer service chat handling skills

MATLAB Camera Calibrator相机标定

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

pymysql 向MySQL 插入数据无故报错

为什么ping不通,而traceroute却可以通

關於ETL看這篇文章就够了,三分鐘讓你明白什麼是ETL
随机推荐
[team management] 25 tips for testing team performance management
【力扣10天SQL入门】Day2
2021-05-20computed和watch应用与区别
【团队管理】测试团队绩效管理的25点小建议
Live broadcast appointment: growth of Mengxin Product Manager
How to handle the problem that calling easycvr address integration cannot be played through easyplayer player?
Redis的Cluster集群数据倾斜
orb slam build bug: undefined reference to symbol ‘_ ZN5boost6system15system_ categoryEv‘
利用sonar做代码检查
MATLAB Camera Calibrator相机标定
lombok 使用
相机投影矩阵计算
小程序wx.show
DataX User Guide
Increase insert speed
Matlab求解线性方程组Ax=b
rpiplay实现树莓派AirPlay投屏器
数据平台简介
微博撰写-流程图-序列图-甘特图-mermaid流程图-效果不错
获取屏幕宽高工具类