Maximum Number of Words Found in Sentences

PHOTO EMBED

Tue Oct 04 2022 18:04:00 GMT+0000 (Coordinated Universal Time)

Saved by @Ranjan_kumar #c++

class Solution {
public:
    int countWords(string str)
{
    // Breaking input into word
    // using string stream
   
    // Used for breaking words
    stringstream s(str);
   
    // To store individual words
    string word;
 
    int count = 0;
    while (s >> word)
        count++;
    return count;
}
    int mostWordsFound(vector<string>& sen) {
        int n=sen.size();
        int maxi=INT_MIN;
        for(int i=0;i<n;i++)
        {
            maxi=max(maxi,countWords(sen[i]));
        }
       return maxi;
    }
};
content_copyCOPY

upper code need to remember or copy from https://www.geeksforgeeks.org/stringstream-c-applications/

https://leetcode.com/problems/maximum-number-of-words-found-in-sentences/