随笔分类 -  字符串

摘要:strcpy #include <iostream> #include <assert.h> using namespace std; char * my_strcpy(char* str1,const char* str2) { char* p = str1; assert(str1 != NUL 阅读全文
posted @ 2020-08-24 09:39 NaughtyCoder 阅读(167) 评论(0) 推荐(0)
摘要:字母异位词分组 题目链接:https://leetcode-cn.com/problems/group-anagrams/ class Solution { public: vector<vector<string>> groupAnagrams(vector<string>& strs) { un 阅读全文
posted @ 2020-08-24 07:58 NaughtyCoder 阅读(137) 评论(0) 推荐(0)
摘要:滑动窗口 维护一个窗口,不断滑动; for(int l = 0, r = 0; r < s.size();) { //增大窗口 win.add(s[r]); r++; //窗口右移 while(满足某个条件) { win.remove(s[l]); l++; //更新某个值 } } 模板 void 阅读全文
posted @ 2020-08-22 17:14 NaughtyCoder 阅读(102) 评论(0) 推荐(0)
摘要:中心扩散法 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; } 阅读全文
posted @ 2020-08-22 11:04 NaughtyCoder 阅读(72) 评论(0) 推荐(0)
摘要:58. II左旋转字符串 题目链接:https://leetcode-cn.com/problems/zuo-xuan-zhuan-zi-fu-chuan-lcof/ class Solution { public: //块交换问题: "abcdefg"; 先交换前2个:"bacdefg"; 再交换 阅读全文
posted @ 2020-08-17 23:07 NaughtyCoder 阅读(64) 评论(0) 推荐(0)
摘要:题目链接:https://leetcode-cn.com/problems/ba-zi-fu-chuan-zhuan-huan-cheng-zheng-shu-lcof/ 应该先去除字符串首部的空格,然后再判断正负。 难点在于处理溢出。 INT_MAX 2147483647 INT_MIN -214 阅读全文
posted @ 2020-05-31 10:14 NaughtyCoder 阅读(106) 评论(0) 推荐(0)
摘要:题目链接: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 阅读全文
posted @ 2020-04-30 08:19 NaughtyCoder 阅读(105) 评论(0) 推荐(0)
摘要:题目链接:https://leetcode-cn.com/problems/fan-zhuan-dan-ci-shun-xu-lcof/ 剑指offer 时间复杂度:O(n) 空间复杂度:O(1) class Solution { public: string reverseWords(string 阅读全文
posted @ 2020-04-09 22:06 NaughtyCoder 阅读(103) 评论(0) 推荐(0)