From 512b045b2a70fce6a61f1c3181202136a20b5886 Mon Sep 17 00:00:00 2001 From: Kyle Hawkins <42872929+killacoug9@users.noreply.github.com> Date: Sun, 2 Mar 2025 16:11:34 -0800 Subject: [PATCH] Found and added bug fix to lcp_array for empty string case. --- cpp/strings/suffix-array.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cpp/strings/suffix-array.cpp b/cpp/strings/suffix-array.cpp index 19e63d49..66d9355c 100644 --- a/cpp/strings/suffix-array.cpp +++ b/cpp/strings/suffix-array.cpp @@ -53,6 +53,9 @@ vector suffix_array(const string &S) { // https://en.wikipedia.org/wiki/LCP_array vector lcp_array(const string &s) { int n = s.size(); + if (n <= 0) + return {}; + vector sa = suffix_array(s); vector rank(n); for (int i = 0; i < n; i++)