Re: [閒聊] 每日leetcode已回收
131. 怕拎奘 切切切
超討厭迴文==寫起來超不奘的
寫出來都看起來超笨超慢超級燒空間
我的問題:(
class Solution {
public:
vector<vector<string>> partition(string s) {
vector<vector<string>> res;
cut(s, res, {});
return res;
}
bool isPa(string& s){
for(int i = 0, j = s.length() -1; i < j; i++, j--){
if(s[i] != s[j]) return false;
}
return true;
}
// cut into 2 substring
// check isPa
void cut(string s, vector<vector<string>>& res, vector<string> v){
if(s == ""){
res.push_back(v);
return;
}
for(int i = 1; i <= s.length(); i++){
string t = s.substr(0, i);
if( isPa(t) ){
v.push_back(t);
cut(s.substr(i, s.length() -i ), res, v);
v.pop_back();
}
}
return;
}
};
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 118.231.168.210 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1716408686.A.DDC.html
→
05/23 04:12,
1年前
, 1F
05/23 04:12, 1F
→
05/23 04:19,
1年前
, 2F
05/23 04:19, 2F
討論串 (同標題文章)
完整討論串 (本文為第 263 之 1553 篇):