Skip to content

Commit e14698e

Browse files
author
applewjg
committed
LongestPalindromicSubstring.h fix a small bug
1 parent 38d8515 commit e14698e

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

LongestPalindromicSubstring.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*
22
Author: Annie Kim, [email protected]
33
Date: Jul 13, 2013
4+
Update: Nov 17, 2014 : By [email protected]
45
Problem: Longest Palindromic Substring
56
Difficulty: Medium
67
Source: http://leetcode.com/onlinejudge#question_5
@@ -67,7 +68,7 @@ class Solution {
6768
for (int i = 0; i < N; ++i) {
6869
for (int j = 0; j <= 1; ++j) {
6970
bool isP = true;
70-
for (int k = 0; i-k >= 0 && i+k < N && isP; ++k) {
71+
for (int k = 0; i-k >= 0 && i+j+k < N && isP; ++k) {
7172
isP = s[i-k] == s[i+j+k];
7273
if (isP && j+1+k*2 > res.second)
7374
res = make_pair(i-k, j+1+k*2);
@@ -107,4 +108,4 @@ class Solution {
107108

108109
return s.substr(res / 2 - (dp[res] - 1) / 2, dp[res] - 1);
109110
}
110-
};
111+
};

0 commit comments

Comments
 (0)