Solution 1: accepted 3ms
DP.
Time: O(n)
Space: O(1)
|
|
DP.
Time: O(n)
Space: O(1)
|
|
|
|
DP
Time: O(mn)
Space: O(mn)
|
|
|
|
Binary solution.
Time: O(logN)
Space: O(1)
|
|
|
|
Super slow! too much operations!
Time: O(n^2)
Space: O(n)
|
|
Though hashSet is more efficient, we can do better.
Time: O(n)
Space: O(n)
|
|
Time: O(n)
Space: O(1)
|
|
|
|
Two pointers.
|
|
Improved to 8ms using Character functions.
|
|
Binary search with wildcard while (lo + 1 < hi)
plus final conditions.
|
|
Alternative
|
|
DP. Still need to look back.
Time: O(n^3), two for loop and s.substring()
Space: O(n)
|
|
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)
Normal iteration.
Time: O(n)
Space: O(1)
|
|
Binary search.
Time: O(logn)
Space: O(1)
We only need to make sure that the board is valid. The worst case is O(n^2) and we will surely come up with a better solution.
Space for speed.
|
|
This is a hard one.
|
|