mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-03-23 06:59:47 +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
123e6f0c33
commit
848a358d80
@ -22,7 +22,9 @@ class SuffixArray:
|
|||||||
"""
|
"""
|
||||||
n = len(self.text)
|
n = len(self.text)
|
||||||
# Create a list of suffix indices sorted by the suffixes they point to
|
# Create a list of suffix indices sorted by the suffixes they point to
|
||||||
sorted_suffix_indices = sorted(range(n), key=lambda suffix_index: self.text[suffix_index:])
|
sorted_suffix_indices = sorted(
|
||||||
|
range(n), key=lambda suffix_index: self.text[suffix_index:]
|
||||||
|
)
|
||||||
return sorted_suffix_indices
|
return sorted_suffix_indices
|
||||||
|
|
||||||
def build_lcp_array(self) -> List[int]:
|
def build_lcp_array(self) -> List[int]:
|
||||||
@ -49,7 +51,9 @@ class SuffixArray:
|
|||||||
for i in range(n):
|
for i in range(n):
|
||||||
if rank[i] > 0:
|
if rank[i] > 0:
|
||||||
j = suffix_array[rank[i] - 1] # Previous suffix in the sorted order
|
j = suffix_array[rank[i] - 1] # Previous suffix in the sorted order
|
||||||
while (i + h < n) and (j + h < n) and self.text[i + h] == self.text[j + h]:
|
while (
|
||||||
|
(i + h < n) and (j + h < n) and self.text[i + h] == self.text[j + h]
|
||||||
|
):
|
||||||
h += 1
|
h += 1
|
||||||
lcp[rank[i]] = h
|
lcp[rank[i]] = h
|
||||||
if h > 0:
|
if h > 0:
|
||||||
@ -77,7 +81,6 @@ class SuffixArray:
|
|||||||
print(f"{suffix_index}: {self.text[suffix_index:]}")
|
print(f"{suffix_index}: {self.text[suffix_index:]}")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Example usage:
|
# Example usage:
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
text = "banana"
|
text = "banana"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user