leetcode 524. Longest Word in Dictionary through Deleting (自定义sort排序cmp)
来源:互联网 发布:ipad编程程序 编辑:程序博客网 时间:2024/06/01 09:21
这题没什么难度,主要训练自定义sort排序熟练程度,还有双指针的熟练程度。
class Solution {public: static bool cmp(const string &a, const string & b) { if (a.size()!=b.size()) { return a.size()>b.size(); } return a<b; } int check(string &s, string &word) { int i=0, j=0; for (;i<word.size()&&j<s.size();) { if (word[i]==s[j]) { ++i; } ++j; } if (i>=word.size()) { return i; } return -1; } string findLongestWord(string s, vector<string>& d) { sort(d.begin(), d.end(), Solution::cmp); int max_len = 0; string res = ""; for (int i=0;i<d.size();++i) { int len = check(s, d[i]); if (len > max_len) { max_len = len; res = d[i]; } } return res; }};
阅读全文
0 0
- leetcode 524. Longest Word in Dictionary through Deleting (自定义sort排序cmp)
- [LeetCode] Longest Word in Dictionary through Deleting
- Leetcode-524. Longest Word in Dictionary through Deleting
- Leetcode 524. Longest Word in Dictionary through Deleting
- LeetCode: 524. Longest Word in Dictionary through Deleting
- LeetCode 524. Longest Word in Dictionary through Deleting
- [LeetCode]524. Longest Word in Dictionary through Deleting
- LeetCode笔记:524. Longest Word in Dictionary through Deleting
- LeetCode 524. Longest Word in Dictionary through Deleting
- leetcode 524. Longest Word in Dictionary through Deleting
- leetcode 524. Longest Word in Dictionary through Deleting
- [Leetcode] 524. Longest Word in Dictionary through Deleting 解题报告
- 524. Longest Word in Dictionary through Deleting
- 524. Longest Word in Dictionary through Deleting
- 524. Longest Word in Dictionary through Deleting
- 524. Longest Word in Dictionary through Deleting
- 524. Longest Word in Dictionary through Deleting
- 524. Longest Word in Dictionary through Deleting
- tensorflow基于GPU环境配置
- The type java.util.Map$Entry cannot be resolved. It is indirectly referenced from required .class fi
- 最短路径
- AntShares 区块链搭建私有链与部署智能合约
- 大zz们的日常
- leetcode 524. Longest Word in Dictionary through Deleting (自定义sort排序cmp)
- 【BZOJ1146】网络管理,整体二分
- tensorflow使用常见问题
- 正则 MULTLINE 属性
- [XJB出题] [分块] 篮球架
- 2017 计蒜之道初赛第5场 UCloud 的安全秘钥(中等)【思维】
- 23种设计模式
- webpack js压缩插件
- 相同程序不同进程下实现数据共享