Leetcode-5013 Index Pairs of a String(字符串的索引对)
依旧没啥好说的
1 #define _for(i,a,b) for(int i = (a);i < b;i ++) 2 3 class Solution 4 { 5 public: 6 vector<vector<int>> indexPairs(string text, vector<string>& words) 7 { 8 set<string> s; 9 vector<vector<int>> v; 10 _for(i,0,words.size()) 11 s.insert(words[i]); 12 13 _for(i,0,text.size()) 14 _for(j,i,text.size()) 15 { 16 string s1; 17 _for(k,i,j+1) 18 s1 += text[k]; 19 20 if(s.count(s1)) 21 { 22 vector<int> tmp; 23 tmp.push_back(i); 24 tmp.push_back(j); 25 v.push_back(tmp); 26 } 27 } 28 return v; 29 } 30 };