Make sure to initialize every variable on declaration!
This commit is contained in:
parent
0b3383ad03
commit
7e791fe554
@ -96,7 +96,7 @@ Result expand(string s, int i) {
|
||||
}
|
||||
|
||||
// 边界情况为长度为 1 的字符时
|
||||
int left1, right1;
|
||||
int left1 = 0, right1 = 0;
|
||||
for (int x = 0; i + x < len && i - x >= 0; x++) {
|
||||
if (s[i - x] == s[i + x]) {
|
||||
left1 = i - x;
|
||||
@ -107,7 +107,7 @@ Result expand(string s, int i) {
|
||||
}
|
||||
|
||||
// 边界情况为长度为 2 的字符串时
|
||||
int left2, right2;
|
||||
int left2 = 0, right2 = 0;
|
||||
for (int x = 0; i + x + 1 < len && i - x >= 0; x++) {
|
||||
if (s[i - x] == s[i + x + 1]) {
|
||||
left2 = i - x;
|
||||
@ -123,7 +123,7 @@ Result expand(string s, int i) {
|
||||
string Solution2::longestPalindrome(string s) {
|
||||
int len = s.length();
|
||||
int left = 0, right = 0;
|
||||
Result result;
|
||||
Result result{0, 0, 0, 0};
|
||||
for (int i = 0; i < len; i++) {
|
||||
result = expand(s, i);
|
||||
if (result.right1 - result.left1 > right - left) {
|
||||
|
Loading…
Reference in New Issue
Block a user