leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

1455.cpp (322B)


      1 class Solution {
      2   public:
      3     int isPrefixOfWord(const string &sentence, const string &searchWord) const {
      4         stringstream ss(sentence);
      5         int idx = 1;
      6         string s;
      7 
      8         while (ss >> s) {
      9             if (s.starts_with(searchWord)) return idx;
     10             idx++;
     11         }
     12 
     13         return -1;
     14     }
     15 };