Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- string longestCommonPrefix(vector<string>& strs) {
- string prefix = strs[0];
- if(strs.size() == 0)
- {
- return "";
- }
- for(int i=1;i<strs.size();i++)
- {
- while(strs[i].find(prefix)!=0)
- {
- prefix=prefix.substr(0,prefix.length()-1);
- }
- if(prefix.length()==0)
- {
- return "";
- }
- }
- return prefix;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment