题解 | 逗号整合器

逗号整合器

https://www.nowcoder.com/practice/ff77cca50f5d4793a14a94f141de0af3

#include <string>
class Solution {
public:
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     * 整理出一个将序列中的数字以逗号隔开从而得到的字符串
     * @param a int整型vector 需要整理的序列 a
     * @return string字符串
     */
    string commaTransformer(vector<int>& a) {
        // write code here
        string s;
        for(auto it=a.begin();it!=a.end();it++){
            if(it!=a.begin())s+=',';
            s+=to_string(*it);
        }
        return s;
    }
};

全部评论

相关推荐

嵌入式的小白:有道理哈,这种就看能不能捞
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务