Solution 1��? time limit exceeded
Time: O(n^2), Space: O(1)
Mutation: Replacing string manipulation with int values, but it dones’t improve the performance.
Solution 2: accepted, 37%
中间��?��?
Time: O(2 n^2), Space: O(1)
avoid unnecessary check, but still O(n^2), failed the “aaaaaaaa…” test case.
We should be able to cut the time to half by check “aba” and “abba” in the same loop:
Solution 3: accepted, 99%
Amaing boost in performace simply because I changed the duplicated code block in solution 2 to method. Is this the truth?
Test case 1
Solution 1: ~100ms
Solution 2: ~6ms (without “len - i < output.length() / 2” it will be 10ms and will not be accepted)
|
|