随笔分类 - 字符串
摘要:strcpy #include <iostream> #include <assert.h> using namespace std; char * my_strcpy(char* str1,const char* str2) { char* p = str1; assert(str1 != NUL
阅读全文
摘要:字母异位词分组 题目链接:https://leetcode-cn.com/problems/group-anagrams/ class Solution { public: vector<vector<string>> groupAnagrams(vector<string>& strs) { un
阅读全文
摘要:滑动窗口 维护一个窗口,不断滑动; for(int l = 0, r = 0; r < s.size();) { //增大窗口 win.add(s[r]); r++; //窗口右移 while(满足某个条件) { win.remove(s[l]); l++; //更新某个值 } } 模板 void
阅读全文
摘要:中心扩散法 int expand(string s, int i, int j) { int n = s.size(); int cnt = 0; while(i >= 0 && j < n) { if(s[i] == s[j]) { cnt++; i--; j++; } else break; }
阅读全文
摘要:58. II左旋转字符串 题目链接:https://leetcode-cn.com/problems/zuo-xuan-zhuan-zi-fu-chuan-lcof/ class Solution { public: //块交换问题: "abcdefg"; 先交换前2个:"bacdefg"; 再交换
阅读全文
摘要:题目链接:https://leetcode-cn.com/problems/ba-zi-fu-chuan-zhuan-huan-cheng-zheng-shu-lcof/ 应该先去除字符串首部的空格,然后再判断正负。 难点在于处理溢出。 INT_MAX 2147483647 INT_MIN -214
阅读全文
摘要:题目链接:https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/ 递归 class Solution { public: int translateNum(int num) { if(num <= 9) re
阅读全文
摘要:题目链接:https://leetcode-cn.com/problems/fan-zhuan-dan-ci-shun-xu-lcof/ 剑指offer 时间复杂度:O(n) 空间复杂度:O(1) class Solution { public: string reverseWords(string
阅读全文