摘要: 重复的子字符串 459. 重复的子字符串 - 力扣(LeetCode) class Solution { public: void getNext (int* next, const string& s){ next[0] = -1; int j = -1; for(int i = 1;i < s. 阅读全文
posted @ 2022-11-20 22:55 凱風快晴 阅读(27) 评论(0) 推荐(0)
摘要: 实现strStr 28. 找出字符串中第一个匹配项的下标 - 力扣(LeetCode) class Solution { public: //構造next前綴表 void getNext(int* next, const string& s){ //从左往右为前缀,从右往左为后缀。 int j = 阅读全文
posted @ 2022-11-18 00:47 凱風快晴 阅读(22) 评论(0) 推荐(0)
摘要: 左旋字符串 剑指 Offer 58 - II. 左旋转字符串 - 力扣(LeetCode) class Solution { public: string reverseLeftWords(string s, int n) { reverse(s.begin(), s.begin() + n); r 阅读全文
posted @ 2022-11-15 21:15 凱風快晴 阅读(16) 评论(0) 推荐(0)
摘要: 反转字符串中的单词 151. 反转字符串中的单词 - 力扣(LeetCode) class Solution { public: void reverse(string& s, int start, int end){ //反转单词字符串,写法为左闭右闭,包括start和end for (int i 阅读全文
posted @ 2022-11-14 23:26 凱風快晴 阅读(22) 评论(0) 推荐(0)
摘要: 反转字符串 344. 反转字符串 - 力扣(LeetCode) class Solution { public: void reverseString(vector<char>& s) { int right = s.size() - 1; for(int left = 0; left<right; 阅读全文
posted @ 2022-11-13 14:57 凱風快晴 阅读(21) 评论(0) 推荐(0)
摘要: 四数之和 18. 四数之和 - 力扣(LeetCode) class Solution { public: vector<vector<int>> fourSum(vector<int>& nums, int target) { vector<vector<int>> result; sort(nu 阅读全文
posted @ 2022-11-12 23:32 凱風快晴 阅读(23) 评论(0) 推荐(0)
摘要: 三数之和 题目链接15. 三数之和 - 力扣(LeetCode) class Solution { public: vector<vector<int>> threeSum(vector<int>& nums) { vector<vector<int>> result; sort(nums.begi 阅读全文
posted @ 2022-11-11 22:59 凱風快晴 阅读(15) 评论(0) 推荐(0)
摘要: 赎金信 题目链接代码随想录 (programmercarl.com) class Solution { public: bool canConstruct(string ransomNote, string magazine) { int record[26] = {0}; if (ransomNo 阅读全文
posted @ 2022-11-10 21:36 凱風快晴 阅读(17) 评论(0) 推荐(0)
摘要: 四数相加II 题目链接454. 四数相加 II - 力扣(LeetCode) class Solution { public: int fourSumCount(vector<int>& nums1, vector<int>& nums2, vector<int>& nums3, vector<in 阅读全文
posted @ 2022-11-09 22:43 凱風快晴 阅读(18) 评论(0) 推荐(0)
摘要: 快乐数 题目链接202. 快乐数 - 力扣(LeetCode) class Solution { public: int getSum(int n){ int sum = 0; while(n){ sum += (n % 10) * (n % 10); n /= 10; } return sum; 阅读全文
posted @ 2022-11-08 23:57 凱風快晴 阅读(26) 评论(0) 推荐(0)