mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-01-18 16:27:02 +00:00
Doctest, type hints and bug in LIS_O(nlogn) (#1525)
* Update longest_increasing_subsequence_o(nlogn).py * Update longest_increasing_subsequence_o(nlogn).py
This commit is contained in:
parent
df95f43907
commit
357dbd4ada
|
@ -4,18 +4,29 @@
|
||||||
# comments: This programme outputs the Longest Strictly Increasing Subsequence in O(NLogN)
|
# comments: This programme outputs the Longest Strictly Increasing Subsequence in O(NLogN)
|
||||||
# Where N is the Number of elements in the list
|
# Where N is the Number of elements in the list
|
||||||
#############################
|
#############################
|
||||||
|
from typing import List
|
||||||
|
|
||||||
def CeilIndex(v, l, r, key):
|
def CeilIndex(v, l, r, key):
|
||||||
while r - l > 1:
|
while r - l > 1:
|
||||||
m = (l + r) / 2
|
m = (l + r) // 2
|
||||||
if v[m] >= key:
|
if v[m] >= key:
|
||||||
r = m
|
r = m
|
||||||
else:
|
else:
|
||||||
l = m
|
l = m
|
||||||
|
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
|
||||||
def LongestIncreasingSubsequenceLength(v):
|
def LongestIncreasingSubsequenceLength(v: List[int]) -> int:
|
||||||
|
"""
|
||||||
|
>>> LongestIncreasingSubsequenceLength([2, 5, 3, 7, 11, 8, 10, 13, 6])
|
||||||
|
6
|
||||||
|
>>> LongestIncreasingSubsequenceLength([])
|
||||||
|
0
|
||||||
|
>>> LongestIncreasingSubsequenceLength([0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15])
|
||||||
|
6
|
||||||
|
>>> LongestIncreasingSubsequenceLength([5, 4, 3, 2, 1])
|
||||||
|
1
|
||||||
|
"""
|
||||||
if len(v) == 0:
|
if len(v) == 0:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
@ -37,5 +48,5 @@ def LongestIncreasingSubsequenceLength(v):
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
v = [2, 5, 3, 7, 11, 8, 10, 13, 6]
|
import doctest
|
||||||
print(LongestIncreasingSubsequenceLength(v))
|
doctest.testmod()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user