1 647. 回文子串
647. 回文子串
纯暴力解法,应该是O(n^3),居然AC了:
class Solution {
public:int countSubstrings(string s) {// 暴力int cnt = 0;cout << s.substr(1,1);for(int i = 0; i < s.size();i++){for(int j = i; j < s.size();j++){ string tmp = s.substr( i , (j-i+1)); // 为O(len)string reverse1 = tmp;reverse(tmp.begin(), tmp.end()); if(reverse1 == tmp)cnt++;}}return cnt;}
};