小编use*_*698的帖子

存储字符串的空间复杂度 O(1)

我对空间复杂度有点困惑。这是 O(1) 空间复杂度还是 O(N) 复杂度?由于我正在创建一个大小为 n 的字符串,所以我的猜测是空间复杂度是 O(N),这是正确的吗?

## this function takes in a string and returns the string

def test(stringval):
stringval2 = ""   
for x in stringval:
   stringval2 = stringval2 + x
return stringval2

test("hello")}
Run Code Online (Sandbox Code Playgroud)

string complexity-theory big-o constants notation

6
推荐指数
1
解决办法
5474
查看次数

标签 统计

big-o ×1

complexity-theory ×1

constants ×1

notation ×1

string ×1