Can anyone help me out with my code to optimise this code.
Question Link-Question Link
Submission Link-Submission
# | User | Rating |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
# | User | Contrib. |
---|---|---|
1 | cry | 165 |
2 | maomao90 | 164 |
3 | Um_nik | 163 |
4 | atcoder_official | 160 |
4 | adamant | 160 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
8 | Dominater069 | 154 |
8 | nor | 154 |
Question Link-Question Link
Submission Link-Submission
Name |
---|
can you provide the submission link, it is difficult to read.
submission Link-https://leetcode.com/playground/gWN5kxkZ
page not found, I cannot access the link.
The maximum length of the input string is $$$1000$$$. You can use a brute-force algorithm to find the answer. Note that threre are $$$1, 2, 3, \ldots, N$$$ Substrings with lengths $$$N, N-1, N-2, \ldots, 1$$$, respectively. Start with Substring length $$$k = N$$$. If one of the $$$N-k+1$$$ Substrings with length $$$k$$$ is palindrome, then return it as the answer. Otherwise, decrement $$$k$$$ and repeat the previous step. If no palindrome Substring is found down to $$$k = 2$$$, then return any 1-letter Substring as the answer.
The following is my Kotlin implementation of the brute-force algorithm if you are interested.
Longest Palinrome Substring
In the recursive function, you are passing the string as pass by value. So if you pass it by value, for every call, the string is copied and adds an additional O(n) complexity.
So just pass the string as pass by reference.