Last night, my dad helped me clean my ear, and accidentally made it bleed. I went to the district hospital early this morning for a checkup. Fortunately, it was nothing serious; only the external ear canal was injured. Rest for a week and it should heal naturally. As long as it does not get infected, it is fine. I was prescribed some amoxicillin. So I skipped the weekly contest and solved the problems after the contest.
1455. Check If a Word Occurs As a Prefix of Any Word in a Sentence
C++ does not have a built-in method for splitting strings, but we can use our own template. Implement the split through stringstream, with O(N) complexity.
Time complexity: O(N), space complexity: O(N).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
classSolution { vector<string> splitSentence(const string& text){ string tmp; vector<string> stk; stringstream ss(text); while(getline(ss,tmp,' ')) { stk.push_back(tmp); } return stk; } public: intisPrefixOfWord(string sentence, string searchWord){ auto words = splitSentence(sentence); for (int i = 0; i < words.size(); ++i) { if (words[i].find(searchWord) == 0) return i + 1; } return-1; } };
1456. Maximum Number of Vowels in a Substring of Given Length
Sliding window. The window size is k, and we count the vowels inside the window.