from __future__ import annotations (#2464)

* from __future__ import annotations

* fixup! from __future__ import annotations

* fixup! from __future__ import annotations

* fixup! Format Python code with psf/black push

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
This commit is contained in:
Christian Clauss
2020-09-23 13:30:13 +02:00
committed by GitHub
parent 6e6a49d19f
commit 9200a2e543
72 changed files with 275 additions and 250 deletions

View File

@ -4,8 +4,9 @@
This program calculates the nth Fibonacci number in O(log(n)).
It's possible to calculate F(1_000_000) in less than a second.
"""
from __future__ import annotations
import sys
from typing import Tuple
def fibonacci(n: int) -> int:
@ -20,7 +21,7 @@ def fibonacci(n: int) -> int:
# returns (F(n), F(n-1))
def _fib(n: int) -> Tuple[int, int]:
def _fib(n: int) -> tuple[int, int]:
if n == 0: # (F(0), F(1))
return (0, 1)

View File

@ -2,12 +2,12 @@
# https://www.guru99.com/fractional-knapsack-problem-greedy.html
# https://medium.com/walkinthecode/greedy-algorithm-fractional-knapsack-problem-9aba1daecc93
from typing import List, Tuple
from __future__ import annotations
def fractional_knapsack(
value: List[int], weight: List[int], capacity: int
) -> Tuple[int, List[int]]:
value: list[int], weight: list[int], capacity: int
) -> tuple[int, list[int]]:
"""
>>> value = [1, 3, 5, 7, 9]
>>> weight = [0.9, 0.7, 0.5, 0.3, 0.1]

View File

@ -5,10 +5,10 @@ You are given a bitmask m and you want to efficiently iterate through all of
its submasks. The mask s is submask of m if only bits that were included in
bitmask are set
"""
from typing import List
from __future__ import annotations
def list_of_submasks(mask: int) -> List[int]:
def list_of_submasks(mask: int) -> list[int]:
"""
Args:

View File

@ -10,10 +10,10 @@ return it.
Example: [10, 22, 9, 33, 21, 50, 41, 60, 80] as input will return
[10, 22, 33, 41, 60, 80] as output
"""
from typing import List
from __future__ import annotations
def longest_subsequence(array: List[int]) -> List[int]: # This function is recursive
def longest_subsequence(array: list[int]) -> list[int]: # This function is recursive
"""
Some examples
>>> longest_subsequence([10, 22, 9, 33, 21, 50, 41, 60, 80])

View File

@ -4,7 +4,7 @@
# comments: This programme outputs the Longest Strictly Increasing Subsequence in
# O(NLogN) Where N is the Number of elements in the list
#############################
from typing import List
from __future__ import annotations
def CeilIndex(v, l, r, key): # noqa: E741
@ -17,7 +17,7 @@ def CeilIndex(v, l, r, key): # noqa: E741
return r
def LongestIncreasingSubsequenceLength(v: List[int]) -> int:
def LongestIncreasingSubsequenceLength(v: list[int]) -> int:
"""
>>> LongestIncreasingSubsequenceLength([2, 5, 3, 7, 11, 8, 10, 13, 6])
6

View File

@ -1,9 +1,9 @@
# Video Explanation: https://www.youtube.com/watch?v=6w60Zi1NtL8&feature=emb_logo
from typing import List
from __future__ import annotations
def maximum_non_adjacent_sum(nums: List[int]) -> int:
def maximum_non_adjacent_sum(nums: list[int]) -> int:
"""
Find the maximum non-adjacent sum of the integers in the nums input list

View File

@ -1,7 +1,7 @@
"""
author : Mayank Kumar Jha (mk9440)
"""
from typing import List
from __future__ import annotations
def find_max_sub_array(A, low, high):
@ -38,7 +38,7 @@ def find_max_cross_sum(A, low, mid, high):
return max_left, max_right, (left_sum + right_sum)
def max_sub_array(nums: List[int]) -> int:
def max_sub_array(nums: list[int]) -> int:
"""
Finds the contiguous subarray which has the largest sum and return its sum.

View File

@ -1,9 +1,9 @@
# Youtube Explanation: https://www.youtube.com/watch?v=lBRtnuxg-gU
from typing import List
from __future__ import annotations
def minimum_cost_path(matrix: List[List[int]]) -> int:
def minimum_cost_path(matrix: list[list[int]]) -> int:
"""
Find the minimum cost traced by all possible paths from top left to bottom right in
a given matrix