Posted on

Description

Submission

class Solution {
public:
    string truncateSentence(string s, int k) {
        auto it = s.begin();

        for(int i = 0; i < k; ++i) {
            it = find(it+1, s.end(), ' ');
        }

        return s.substr(0, it - s.begin());
    }   
};

Leave a Reply

Your email address will not be published. Required fields are marked *