It refers to the relationship between the algorithm storage space and the input value .
Common space complexity :O(1)、O(n)、O(n^2)
O(1)<O(n)<O(n^2)
O(1)
def test(num):
total=0
for i in range(num):
total += i
return total
O(n)
def test(nums):
array=[]
for num in range(nums):
array.append(num)
return array
You can only choose between time and space
During the interview : Clarify with the interviewer
Working hours : Time is greater than space