Longest substring computational complexity

后端 未结 3 1036
臣服心动
臣服心动 2021-02-06 19:41

I was wondering about my apparently code for an MIT online edx class practice problem vs the provided answer code.

The assignment in question from the class was

3条回答
  •  鱼传尺愫
    2021-02-06 19:53

    Their answer code is more efficient because it does not repeatedly iterate through subsequences. Given the subsequence ABCDE, your code separately processes BCDE, CDE, and DE in successive iterations even though they cannot be longest.

    Therefore, the worst-case runtime of your answer is O(N^2) vs. O(N) for theirs. Yes, this is related to having a nested for loop which is not present in their answer.

提交回复
热议问题