416. Partition Equal Subset Sum

01 背包問題

https://labuladong.github.io/algo/3/27/81/

transform problem into 01 knapsack

https://labuladong.github.io/algo/3/27/82/

time: (n*m), n is nums size, m = sum/2

space: (n*m)

1D space

T: O(mn)

S: O(n)

或者把 j >= nums[i-1] 寫在 for loop 就可以了, 少一個 if 條件

Last updated

Was this helpful?