Can anyone help me out with my code to optimise this code.
Question Link-Question Link
Submission Link-Submission
# | User | Rating |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | Dominater069 | 154 |
8 | awoo | 154 |
10 | luogu_official | 150 |
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.