Test cases
|
|
Solution 1: accepted 13ms
DP. Still need to look back.
Time: O(n^3), two for loop and s.substring()
Space: O(n)
|
|
Solution 2
Based on the list. We could use this one if the list is very long, since solution 1 needs to iterate the entire list all the time.
Time: O(n^2)
Space: O(n)