3042. 统计前后缀下标对 I
思路:两层for循环进行模拟
class Solution {
public:
bool check(string s1,string s2){
bool flag=1;
for(int i=0;i<s1.size();i++){
if(s1[i]!=s2[i]){
flag=0;
break;
}
}
for(int i=s1.size()-1,j=s2.size()-1;i>=0;i--,j--){
if(s1[i]!=s2[j]){
flag=0;
break;
}
}
return flag;
}
int countPrefixSuffixPairs(vector<string>& words) {
int ans=0;
for(int i=0;i<words.size();i++){
for(int j=i+1;j<words.size();j++){
if(words[i].size()<=words[j].size()&&check(words[i],words[j])) ans++;
}
}
return ans;
}
};