2255. Count Prefixes of a Given String 發表於 2023-02-13 | 分類於 leetcode problemsolution1234567891011121314class Solution {public: int countPrefixes(vector<string>& words, string s) { int count = 0 ; for(int i=0;i<s.size();++i){ string temp = s.substr(0,i+1); for(const auto word:words){ if(word == temp) count++; } } return count; }}; analysis time complexity O(nm) space complexity O(n)