GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Doctest, type hints and bug in LIS_O(nlogn) (#1525) · jusing-es/Python@357dbd4

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • dynamic_programming
    • longest_increasing_subsequence_o(nlogn).py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎dynamic_programming/longest_increasing_subsequence_o(nlogn).py‎

Copy file name to clipboardExpand all lines: dynamic_programming/longest_increasing_subsequence_o(nlogn).py
+16-5Lines changed: 16 additions & 5 deletions
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 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.