Fix s0005 solution2
All checks were successful
continuous-integration/drone/push Build is passing

Make sure to initialize every variable on declaration!
This commit is contained in:
Sainnhe Park 2022-11-02 17:39:35 +08:00
parent 0b3383ad03
commit 7e791fe554

View File

@ -96,7 +96,7 @@ Result expand(string s, int i) {
} }
// 边界情况为长度为 1 的字符时 // 边界情况为长度为 1 的字符时
int left1, right1; int left1 = 0, right1 = 0;
for (int x = 0; i + x < len && i - x >= 0; x++) { for (int x = 0; i + x < len && i - x >= 0; x++) {
if (s[i - x] == s[i + x]) { if (s[i - x] == s[i + x]) {
left1 = i - x; left1 = i - x;
@ -107,7 +107,7 @@ Result expand(string s, int i) {
} }
// 边界情况为长度为 2 的字符串时 // 边界情况为长度为 2 的字符串时
int left2, right2; int left2 = 0, right2 = 0;
for (int x = 0; i + x + 1 < len && i - x >= 0; x++) { for (int x = 0; i + x + 1 < len && i - x >= 0; x++) {
if (s[i - x] == s[i + x + 1]) { if (s[i - x] == s[i + x + 1]) {
left2 = i - x; left2 = i - x;
@ -123,7 +123,7 @@ Result expand(string s, int i) {
string Solution2::longestPalindrome(string s) { string Solution2::longestPalindrome(string s) {
int len = s.length(); int len = s.length();
int left = 0, right = 0; int left = 0, right = 0;
Result result; Result result{0, 0, 0, 0};
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
result = expand(s, i); result = expand(s, i);
if (result.right1 - result.left1 > right - left) { if (result.right1 - result.left1 > right - left) {