题目
编写一个函数来查找字符串数组中的最长公共后缀,如果不存在公共后缀,返回固定字符串:@Zero.
补充说明:
1、字符串长度范围:[2,1000];
2、字符串中字符长度范围为[1,126]
输入描述
一个字符串数组
["abc""bbc" c]
输出描述
一个字符串
示例1:
输入:
["abc","bbc","bc"]
输出:
c
说明:
返回公共后缀: c
示例2:
输入:
["aa","bb","cc"]
输出:
"@Zero"
说明:
不存在公共后缀,返回固定结果: @Zero
代码
#include <iostream>
#include<string>
#include <vector>
#include<algorithm>
using namespace std;
string process(vector<string>zifu)
{
string tmp = zifu[0];
reverse(tmp.begin(), tmp.end());
for (int i = 1; i < zifu.size(); i++)
{
string str1 = zifu[i];
reverse(str1.begin(), str1.end());
for (int j =