Skip to content

Commit 732aaf2

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 36bef76 commit 732aaf2

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

strings/suffix_array.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
'''
1+
"""
22
suffix_array.py
33
44
Professional implementation of Suffix Array and LCP (Longest Common Prefix) array in Python.
@@ -11,7 +11,8 @@
1111
1212
Author: Idris Ibrahim Erten
1313
License: MIT
14-
'''
14+
"""
15+
1516

1617
def build_suffix_array(s: str) -> list[int]:
1718
"""
@@ -27,7 +28,7 @@ def build_suffix_array(s: str) -> list[int]:
2728
O(n log n) time and O(n) space.
2829
"""
2930
# Append a sentinel that is lexicographically smaller than all other characters
30-
s += '\0'
31+
s += "\0"
3132
n = len(s)
3233
# Initial ranking by character code
3334
ranks = [ord(c) for c in s]
@@ -89,9 +90,9 @@ def build_lcp_array(s: str, sa: list[int]) -> list[int]:
8990
return lcp[1:]
9091

9192

92-
if __name__ == '__main__':
93+
if __name__ == "__main__":
9394
# Example usage and simple tests
94-
test_strings = ['banana', 'abracadabra', 'mississippi']
95+
test_strings = ["banana", "abracadabra", "mississippi"]
9596
for s in test_strings:
9697
sa = build_suffix_array(s)
9798
lcp = build_lcp_array(s, sa)
@@ -100,7 +101,7 @@ def build_lcp_array(s: str, sa: list[int]) -> list[int]:
100101
print(f"LCP Array : {lcp}\n")
101102

102103
# Assertions for correctness
103-
s = 'banana'
104+
s = "banana"
104105
expected_sa = [5, 3, 1, 0, 4, 2] # indices of sorted suffixes
105-
assert build_suffix_array(s) == expected_sa, 'SA test failed'
106-
print('All tests passed!')
106+
assert build_suffix_array(s) == expected_sa, "SA test failed"
107+
print("All tests passed!")

0 commit comments

Comments
 (0)