Leetcode—2788. 按分隔符拆分字符串【简单】(stringstream的应用)

2023每日刷题(八十六)

Leetcode---2788. 按分隔符拆分字符串

实现代码

cpp 复制代码
class Solution {
public:
    vector<string> splitWordsBySeparator(vector<string>& words, char separator) {
        vector<string> res;
        for(auto word: words) {
            stringstream ss(word);
            string sub;
            while(getline(ss, sub, separator)) {
                if(!sub.empty()) {
                    res.push_back(sub);
                }
            }
        }
        return res;
    }
};

运行结果


之后我会持续更新,如果喜欢我的文章,请记得一键三连哦,点赞关注收藏,你的每一个赞每一份关注每一次收藏都将是我前进路上的无限动力 !!!↖(▔▽▔)↗感谢支持!

相关推荐
whxnchy20 小时前
UDP多端口负载均衡实战
c++
sheeta199821 小时前
LeetCode 每日一题笔记 日期:2026.05.08 题目:3629. 素数跳跃最小次数
笔记·算法·leetcode
叼烟扛炮21 小时前
C++ 知识点08 类与对象
开发语言·c++·算法·类和对象
米粒121 小时前
力扣算法刷题 Day 63 Bellman_ford 算法
数据库·算法·leetcode
楼田莉子21 小时前
仿Muduo的高并发服务器:Http协议模块
linux·服务器·c++·后端·学习
IT大白鼠1 天前
AIGC性能的关键瓶颈:算力、数据、算法三者如何互相制约?
算法·aigc
tjl521314_211 天前
04C++ 名称空间(Namespace)
开发语言·c++
ximu_polaris1 天前
设计模式(C++)-行为型模式-备忘录模式
c++·设计模式·备忘录模式
白雪茫茫1 天前
监督学习、半监督学习、无监督学习算法详解
python·学习·算法·ai
FengyunSky1 天前
浅析 空间频率响应 SFR 计算
算法