818. Race Car

T: O(2^n) since for each position we have two choices: either accelerate or reverse

S: O(2^n)

其中如果限制了這部分, 可以加快速度, 因為如果今天不小心超過 target 太多時, 其實是不合理的, 要倒車很多次

所以有一個界線會有差 可以 target*1.5 ~ target*2

我認為是因為每次增加都是 2的次方倍數速度增加, 所以不小心超過時, 1.5倍應該是可以容許的範圍

DP - 最優解

T: O(n * (logn)^2 ), n is target

S: O(n)

Last updated

Was this helpful?