精華區beta Marginalman 關於我們 聯絡資訊
題目: 可以從中間插入“單字” 不能直接接字 要有空格那種 看能不能把兩個橘子變一樣 思路: 把他變成一個字單一個單字的vector 然後再two pointer 我要打手槍 ```cpp class Solution { public: bool areSentencesSimilar(string sentence1, string sentence2) { sentence1 += " "; sentence2 += " "; int n1 = sentence1.size(); int n2 = sentence2.size(); vector<string> w1; vector<string> w2; int l = 0; int r = 0; string xd; for(int i = 0 ; i < n1 ; i ++) { if(sentence1[i] == ' ') { w1.push_back(xd); xd.clear(); } else { xd.push_back(sentence1[i]); } } for(int i = 0 ; i < n2 ; i ++) { if(sentence2[i] == ' ') { w2.push_back(xd); xd.clear(); } else { xd.push_back(sentence2[i]); } } for( ; l < min(w1.size() ,w2.size() ); l ++) { if(w1[l] != w2[l]) break; } for( ; r < min(w1.size() ,w2.size() ); r ++) { if(w1[w1.size()-1-r] != w2[w2.size()-1-r]) break; } return (l+r >= min(w1.size() ,w2.size() )); } };``` -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 134.208.237.130 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1728192672.A.F14.html
CanIndulgeMe: 東大資工的榮耀 10/06 13:33
CanIndulgeMe: 你終於使用學網的IP了 10/06 13:33
oin1104: 真的欸 134.208 10/06 13:34
JIWP: 我好佩服你 10/06 13:34
sixB: 大學生真的好厲害 10/06 13:56