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;
}
};
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter