Longest Palindrome Substring: C++ and TypeScript Solutions
class Solution {\n public: \n string longestPalindrome(string s) { \n string res="",temp=""; \n for(int i=0;i<s.size();i++){ \n for(int j=i;j<s.size();j++){ \n temp+=s[j]; \n string tem=temp; \n reverse(tem.begin(),tem.end()); \n if(temp==tem) res=res.length()>temp.length()?res:temp; \n } \n temp=""; \n } \n return res; \n } \n};//转换成TypeScript内容:class Solution { \n longestPalindrome(s: string): string { \n let res: string = ""; \n let temp: string = ""; \n for(let i: number = 0; i < s.length; i++){ \n for(let j: number = i; j < s.length; j++){ \n temp += s[j]; \n let tem: string = temp; \n tem = tem.split('').reverse().join(''); \n if(temp === tem) res = res.length > temp.length ? res : temp; \n } \n temp = ""; \n } \n return res; \n } \n}
原文地址: https://www.cveoy.top/t/topic/p2VJ 著作权归作者所有。请勿转载和采集!