Skip to content

Commit 357dbd4

Browse files
authoredOct 30, 2019
Doctest, type hints and bug in LIS_O(nlogn) (TheAlgorithms#1525)
* Update longest_increasing_subsequence_o(nlogn).py * Update longest_increasing_subsequence_o(nlogn).py
1 parent df95f43 commit 357dbd4

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed
 

‎dynamic_programming/longest_increasing_subsequence_o(nlogn).py

+16-5
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,29 @@
44
# comments: This programme outputs the Longest Strictly Increasing Subsequence in O(NLogN)
55
# Where N is the Number of elements in the list
66
#############################
7+
from typing import List
8+
79
def CeilIndex(v, l, r, key):
810
while r - l > 1:
9-
m = (l + r) / 2
11+
m = (l + r) // 2
1012
if v[m] >= key:
1113
r = m
1214
else:
1315
l = m
14-
1516
return r
1617

1718

18-
def LongestIncreasingSubsequenceLength(v):
19+
def LongestIncreasingSubsequenceLength(v: List[int]) -> int:
20+
"""
21+
>>> LongestIncreasingSubsequenceLength([2, 5, 3, 7, 11, 8, 10, 13, 6])
22+
6
23+
>>> LongestIncreasingSubsequenceLength([])
24+
0
25+
>>> LongestIncreasingSubsequenceLength([0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15])
26+
6
27+
>>> LongestIncreasingSubsequenceLength([5, 4, 3, 2, 1])
28+
1
29+
"""
1930
if len(v) == 0:
2031
return 0
2132

@@ -37,5 +48,5 @@ def LongestIncreasingSubsequenceLength(v):
3748

3849

3950
if __name__ == "__main__":
40-
v = [2, 5, 3, 7, 11, 8, 10, 13, 6]
41-
print(LongestIncreasingSubsequenceLength(v))
51+
import doctest
52+
doctest.testmod()

0 commit comments

Comments
 (0)