Skip to content

Commit 86ecfee

Browse files
committed
修复可能越界的bug
1 parent ebb384b commit 86ecfee

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

C++/chapDFS.tex

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ \subsubsection{深搜1}
6363
}
6464

6565
bool isPalindrome(const string &s, int start, int end) {
66-
while (s[start] == s[end]) {
66+
while (start < end && s[start] == s[end]) {
6767
++start;
6868
--end;
6969
}
@@ -101,7 +101,7 @@ \subsubsection{深搜2}
101101
}
102102
}
103103
bool isPalindrome(const string &s, int start, int end) {
104-
while (s[start] == s[end]) {
104+
while (start < end && s[start] == s[end]) {
105105
++start;
106106
--end;
107107
}

0 commit comments

Comments
 (0)