Can stringstream be allowed in this question? C++


  • 0
    X
    class Solution {
    public:
        void reverseWords(string &s) {
            vector<string> wordList;
            stringstream wordStream(s);
            string word;
            while (wordStream >> word)
              wordList.push_back(word);
            
            string des = "";
            int i = wordList.size() - 1;
            for (; i > 0; i--)
              des += wordList[i] + " ";
            if (i == 0)
              des += wordList[i];
            s = des;
        }
    };
    

    My code use stringstream to solve this problem, is it allowed in real interview?
    Thanks!


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.