摘要: 题目链接 解题思路:简单模拟 class Solution { public: string convert(string s, int numRows) { if(numRows==1){ return s; } int L=(numRows-1)*2; int R=0; int len=s.si 阅读全文
posted @ 2022-01-25 18:52 夜灯长明 阅读(28) 评论(0) 推荐(0) 编辑
摘要: 题目链接 解题思路:简单模拟即可 class Solution { public: int numberOfMatches(int n) { int sum=0; while(n!=1){ if(n%2==0){ n=n>>1; sum+=n; } else{ n=n>>1; sum+=n; n++ 阅读全文
posted @ 2022-01-25 18:02 夜灯长明 阅读(8) 评论(0) 推荐(0) 编辑
摘要: 题目链接 动态规划 class Solution { public: string longestPalindrome(string s) { int begin=0; int n=s.size(); int Max=1; vector<vector<int>>dp(n,vector<int>(n) 阅读全文
posted @ 2022-01-25 17:53 夜灯长明 阅读(20) 评论(0) 推荐(0) 编辑
摘要: 参考博客 该算法可以在时间空间都为O(n),求出最大的回文子串 string longestPalindrome(string s) { string str; string ans; int start=0, end=0; str += "$#"; for (int i = 0; i < s.si 阅读全文
posted @ 2022-01-25 17:45 夜灯长明 阅读(23) 评论(0) 推荐(0) 编辑