mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-02-12 04:18:08 +00:00
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
c7f137eefc
commit
8038826cd9
|
@ -2,6 +2,7 @@
|
|||
|
||||
import doctest
|
||||
|
||||
|
||||
def build_suffix_array(s: str) -> list[int]:
|
||||
"""
|
||||
Build the suffix array for the given string.
|
||||
|
@ -22,6 +23,7 @@ def build_suffix_array(s: str) -> list[int]:
|
|||
suffix_array = [suffix[1] for suffix in suffixes]
|
||||
return suffix_array
|
||||
|
||||
|
||||
def build_lcp_array(s: str, suffix_array: list[int]) -> list[int]:
|
||||
"""
|
||||
Build the LCP array for the given string and suffix array.
|
||||
|
@ -58,6 +60,7 @@ def build_lcp_array(s: str, suffix_array: list[int]) -> list[int]:
|
|||
h -= 1 # Decrease h for the next suffix
|
||||
return lcp
|
||||
|
||||
|
||||
# Example usage
|
||||
if __name__ == "__main__":
|
||||
s = "banana"
|
||||
|
@ -70,8 +73,10 @@ if __name__ == "__main__":
|
|||
|
||||
print("\nLCP Array:")
|
||||
for i in range(1, len(lcp_array)):
|
||||
lcp_info = (f"LCP between {s[suffix_array[i - 1]:]} and "
|
||||
f"{s[suffix_array[i]]}: {lcp_array[i]}")
|
||||
lcp_info = (
|
||||
f"LCP between {s[suffix_array[i - 1]:]} and "
|
||||
f"{s[suffix_array[i]]}: {lcp_array[i]}"
|
||||
)
|
||||
print(lcp_info)
|
||||
|
||||
# Run doctests
|
||||
|
|
Loading…
Reference in New Issue
Block a user