字符串
沙扬娜拉的裙裾
刚刚步入计算机大军的小草虚心请教
展开
-
真实面试题-消消乐连续三个或者三个以上字符消除
题目如:abbbaac消除结果是c因为leetcode也没有刷题链接,所以自己写了几个测试用例通过了一下,以下是代码:string xiaoxiaole(string s){ if(s.length()<=2) return s; stack<char> save; save.push(s[0]); int count=1; int i=1; string res = "";原创 2020-10-12 00:11:31 · 1948 阅读 · 1 评论 -
leetcode#20-有效的括号
class Solution {public: bool isValid(string s) { if(s.length()<=0) return true; stack<char> save; if(s[0]=='('||s[0]=='['||s[0]=='{') save.push(s[0]); else return false; int i=1; while(i<s.length()){ i.原创 2020-09-03 12:36:11 · 93 阅读 · 0 评论 -
leetcode#131-分割回文串
class Solution {public: vector<vector<string>> res; vector<vector<string>> partition(string s) { if(s.length()<=0) return res; vector<string> path; back(s,path,0);//从第0个位置开始,一路遍历到最后一个字符 return res;.原创 2020-08-29 18:51:20 · 101 阅读 · 0 评论 -
leetcode#127-字符串的最短转换序列
class Solution {public: int ladderLength(string beginWord, string endWord, vector<string>& wordList) { unordered_set<string> dict(wordList.begin(), wordList.end());//把字典中的字符变成hash_set加速查找 unordered_map<string, int&g.原创 2020-08-29 15:08:50 · 361 阅读 · 0 评论 -
leetcode#125-验证回文串
class Solution {public: bool isPalindrome(string s) { if(s.length()<=1) return true; int begin = 0; int end = s.length()-1; while(begin<end){ while(begin<end && !((s[begin]>='a' &&am.原创 2020-08-21 09:55:54 · 80 阅读 · 0 评论