336. Palindrome Pairs
来源:互联网 发布:免费平面图绘图软件 编辑:程序博客网 时间:2024/04/29 17:47
class Solution {public: bool isPalin(string tmp) { int n=tmp.size(); int i=0,j=n-1; while(i<j) { if(tmp[i]!=tmp[j]) return false; i++; j--; } return true; } vector<vector<int>> palindromePairs(vector<string>& words) { vector<vector<int>> ans; unordered_map<string,int> dict; int n=words.size(); int i,j; for(i=0;i<n;i++) dict[words[i]]=i; for(i=0;i<n;i++) { int len=words[i].size(); dict.erase(words[i]); for(j=0;j<=len;j++) { string sl=words[i].substr(0,j); string sr=words[i].substr(j); string revL(sl.rbegin(),sl.rend()); string revR(sr.rbegin(),sr.rend()); if(isPalin(sl)&&dict.find(revR)!=dict.end()) { ans.push_back(vector<int>{dict[revR],i}); } if(j!=len&&isPalin(sr)&&dict.find(revL)!=dict.end()) { ans.push_back(vector<int>{i,dict[revL]}); } } dict[words[i]]=i; } return ans; }};
0 0
- LeetCode 336. Palindrome Pairs
- LeetCode 336. Palindrome Pairs
- leetcode 336. Palindrome Pairs
- LeetCode 336. Palindrome Pairs
- leetcode.336. Palindrome Pairs
- 336. Palindrome Pairs
- 336. Palindrome Pairs
- [leetcode] 336. Palindrome Pairs
- 336. Palindrome Pairs
- LeetCode-336.Palindrome Pairs
- LeetCode 336. Palindrome Pairs
- 336. Palindrome Pairs
- 336. Palindrome Pairs
- [LeetCode]336. Palindrome Pairs
- 336. Palindrome Pairs
- 336. Palindrome Pairs
- leetcode 336. Palindrome Pairs
- 336. Palindrome Pairs
- 第四周项目6—— 多项式求和
- 第25周-window程序设计(基础篇)-第3章-注册窗口类别2
- [Leetcode] Binary Search Tree Iterator
- 欢迎使用CSDN-markdown编辑器
- 有类似范、36、瘾技的外网推荐一下么?
- 336. Palindrome Pairs
- 数据库中的事务的特性和隔离级别 MindJet整理
- 海思3520DV300编译mp4v2
- Android 导航条效果实现(六) TabLayout+ViewPager+Fragment
- OC内存管理
- POJ3468 A Simple Problem with Integers
- RecyclerView初体验
- 一,7,0手动内存管理基本概念
- centos7 下搭建lighttpd+php+mysql