From 2feb037ca90508a1b081cd736c29f658507cb5f2 Mon Sep 17 00:00:00 2001 From: Nischay mrzn <129774293+Nischaymrzn@users.noreply.github.com> Date: Wed, 30 Oct 2024 11:01:57 +0545 Subject: [PATCH] Create Climbing_Stairs.py --- Python/Climbing_Stairs.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Python/Climbing_Stairs.py diff --git a/Python/Climbing_Stairs.py b/Python/Climbing_Stairs.py new file mode 100644 index 0000000..df884e6 --- /dev/null +++ b/Python/Climbing_Stairs.py @@ -0,0 +1,33 @@ +def climb_stairs(number_of_steps: int) -> int: + """ + LeetCdoe No.70: Climbing Stairs + Distinct ways to climb a number_of_steps staircase where each time you can either + climb 1 or 2 steps. + + Args: + number_of_steps: number of steps on the staircase + + Returns: + Distinct ways to climb a number_of_steps staircase + + Raises: + AssertionError: number_of_steps not positive integer + + >>> climb_stairs(3) + 3 + >>> climb_stairs(1) + 1 + >>> climb_stairs(-7) # doctest: +ELLIPSIS + Traceback (most recent call last): + ... + AssertionError: number_of_steps needs to be positive integer, your input -7 + """ + assert ( + isinstance(number_of_steps, int) and number_of_steps > 0 + ), f"number_of_steps needs to be positive integer, your input {number_of_steps}" + if number_of_steps == 1: + return 1 + previous, current = 1, 1 + for _ in range(number_of_steps - 1): + current, previous = current + previous, current + return current