
字符串
leetcode字符串
三Ⅶ
这个作者很懒,什么都没留下…
展开
-
14. 最长公共前缀
方法一:纵向遍历 遍历每一个字符串的第一个字符,若相同,在前缀p上加上该字符,遍历第二个,若相同,加上p,若不相同。返回p class Solution { public: string longestCommonPrefix(vector<string>& strs) { if(strs.size()==0) { return ""; } int j=0; st原创 2021-06-05 13:49:40 · 78 阅读 · 0 评论 -
5. 最长回文子串
回文串有两种情况,一种是以cac这种奇数回文串,一种是baab这种偶数回文串,我们在解答时需要同时考虑这两种情况。 大致思路:我们创建一个查找回文字符串的函数,并返回其回文字符串的边界。 class Solution { public: pair<int ,int >ex(const string& s, int left, int right) { while (left >= 0 && right < s.size() .原创 2021-06-05 11:12:42 · 67 阅读 · 0 评论