524. Longest Word in Dictionary through Deleting
来源:互联网 发布:tp框架数据库修改语句 编辑:程序博客网 时间:2024/05/17 01:46
简单题,关键在于题意的理解。lexicographical order指的是按照字母顺序排序。
class Solution {public: static bool cmp(string& a,string& b) { if(a.length()>b.length()) return true; else if(a.length()==b.length()) { if(a.compare(b)<0) return true; else return false; } else return false; } bool judge(string strShort,string strLong) { if(strLong.length()<strShort.length()) return false; else { int index1=0; int index2=0; while(index1<strShort.length()&&index2<strLong.length()) { if(strShort[index1]==strLong[index2]) { index1++; index2++; } else index2++; } if(index1==strShort.length()) return true; else return false; } } string findLongestWord(string s, vector<string>& d) { sort(d.begin(),d.end(),cmp); for(int i=0;i<d.size();i++) { if(judge(d[i],s)==true) return d[i]; } return ""; }};
0 0
- 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
- 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
- Longest Word in Dictionary through Deleting
- leetcode524~Longest Word in Dictionary through Deleting
- [LeetCode] Longest Word in Dictionary through Deleting
- Longest Word in Dictionary through Deleting
- Longest Word in Dictionary through Deleting
- Leetcode-524. Longest Word in Dictionary through Deleting
- [绍棠] [iOS 10 打包静态库支持armv7] 静态库打包 .a armv7
- CSS3属性兼容处理
- 修正Linux下WPS字体库缺失
- Oracle复杂查询(三)
- 微信公众平台开发入门教程
- 524. Longest Word in Dictionary through Deleting
- 当IE8 background-color不生效时
- java通过jni调用tuxedo
- Idea的使用与感受(三)
- 系统测试
- JS function length的含义
- HTML5的新特性--基础知识(3)
- js中的hasOwnProperty和isPrototypeOf方法使用实例
- 递归-动物生崽问题