648. Replace Words
来源:互联网 发布:论坛模板源码 编辑:程序博客网 时间:2024/05/29 16:16
简单题,但是需要把原来的问题分解成多个步骤
class Solution {public: string find(string s, set<string>& newDict) { for(int i=0;i<s.size();i++) { string temp = s.substr(0,i+1); if(newDict.find(temp)!=newDict.end()) return temp; } return s; } string replaceWords(vector<string>& dict, string s) { vector<string> split; int start= 0; int end=0; while(start<s.size()&&end<s.size()) { while(s[start]==' ') start++; end=start; while(end<s.size()&&s[end]!=' ') end++; split.push_back(s.substr(start, end-start)); start=end; } set<string> newDict; for(int i=0;i<dict.size();i++) newDict.insert(dict[i]); string result = ""; for(int i=0;i<split.size()-1;i++) result+=find(split[i], newDict)+" "; result+=find(split[split.size()-1], newDict); return result; }};
阅读全文
0 0
- 648. Replace Words
- Leetcode--648. Replace Words
- 648. Replace Words
- leetcode 648. Replace Words
- 648. Replace Words
- 648. Replace Words
- 648. Replace Words
- leetcode-648. Replace Words
- leetcode 648. Replace Words
- leetcode 648. Replace Words
- 648. Replace Words
- 648. Replace Words
- Replace Words
- LeetCode 648. Replace Words 字典树练习
- leetcode 648. Replace Words 字典树
- 【LeetCode】648.Replace Words(Medium)解题报告
- leetcode 648. Replace Words 公共前缀
- LeetCode.648 Replace Words
- 第二章作业题3-链表(2)
- python skimage 连通性区域检测
- 1123. Is It a Complete AVL Tree (30)
- 小程序--注释转换(C to c++)
- 页面布局设计杂记
- 648. Replace Words
- wireshark使用抓包详细图文教程
- xamarin学习笔记B06(ios的Autolayout布局)
- oracle12c plsql cann't access
- Servlet 工程 web.xml 中的 servlet 和 servlet-mapping 标签
- Lintcode174 Remove Nth Node From End of List solution 题解
- wireshark过滤MAC地址/物理地址
- 揭开“流量劫持”的神秘面纱:月入至少三万
- linux 下创建和删除软连接