mirror of
https://github.com/krahets/hello-algo.git
synced 2024-12-24 10:46:29 +08:00
Add return value for recur function of Python in space complexity (#1169)
* Add return value for recur function of Python in space complexity * Update space_complexity.md * Update space_complexity.md --------- Co-authored-by: Yudong Jin <krahets@163.com>
This commit is contained in:
parent
739ee24751
commit
55db99ab18
2 changed files with 6 additions and 4 deletions
|
@ -476,9 +476,10 @@ Consider the following code, the term "worst-case" in worst-case space complexit
|
|||
for _ in range(n):
|
||||
function()
|
||||
|
||||
def recur(n: int) -> int:
|
||||
def recur(n: int):
|
||||
"""Recursion O(n)"""""
|
||||
if n == 1: return
|
||||
if n == 1:
|
||||
return
|
||||
return recur(n - 1)
|
||||
```
|
||||
|
||||
|
|
|
@ -475,9 +475,10 @@
|
|||
for _ in range(n):
|
||||
function()
|
||||
|
||||
def recur(n: int) -> int:
|
||||
def recur(n: int):
|
||||
"""递归的空间复杂度为 O(n)"""
|
||||
if n == 1: return
|
||||
if n == 1:
|
||||
return
|
||||
return recur(n - 1)
|
||||
```
|
||||
|
||||
|
|
Loading…
Reference in a new issue