题目连接:
其实,这个题很简单,两层循环遍历数组,定义一个变量count用来计数,只要满足words[i][0] == words[j][1] && words[i][1] == words[j][0]这个条件,count自增1即可
代码如下:
int maximumNumberOfStringPairs(char ** words, int wordsSize){
int count = 0;
for(int i = 0;i < wordsSize;i++)
{
for(int j = i+1;j < wordsSize;j++)
{
if(words[i][0] == words[j][1] && words[i][1] == words[j][0])
{
count++;
}
}
}
return count;
}