马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 瓜瓜咚 于 2020-11-30 16:44 编辑 #include <iostream>
#include <vector>
#include <utility>
#include <string>
using namespace std;
pair<int, int> expandAroundCenter(const string& s, int left, int right) {
while (left >=0 && right < s.size() && s[left] == s[right]) {
--left;
++right;
}
return {left + 1, right - 1};
}
string longestPalindrome(string s) {
int start = 0, end = 0;
// int left1, left2, right1, right2;
for (int i = 0; i < s.size(); ++i) {
auto [left1, right1] = expandAroundCenter(s, i, i);
auto [left2, right2] = expandAroundCenter(s, i, i + 1);
if (right1 - left1 > end - start) {
start = left1;
end = right1;
}
if (right2 - left2 > end - start) {
start = left2;
end = right2;
}
}
return s.substr(start, end - start + 1);
}
在longestPalindrome函数中auto [left1, right1]和auto [left2, right2]这两句话显示left1, left2, right1, right2未定义,求助大佬这个地方应该怎么用? |