02 2022 档案

摘要:class Solution { public: string frequencySort(string s) { int dict_s[300]; memset(dict_s, 0, sizeof(dict_s)); for(auto ch : s) dict_s[ch] ++; sort(s.b 阅读全文
posted @ 2022-02-28 20:07 fwx 阅读(17) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: string findLongestWord(string s, vector<string>& dictionary) { vector<string> match_s; for(auto dict_s : dictionary){ int j = 阅读全文
posted @ 2022-02-28 20:06 fwx 阅读(22) 评论(0) 推荐(0) 编辑
摘要:双指针 O(sqrt(n)): class Solution { public: bool judgeSquareSum(int c) { long long left = 0, right = sqrt(c); while(left <= right){ long long sum = left 阅读全文
posted @ 2022-02-28 20:04 fwx 阅读(16) 评论(0) 推荐(0) 编辑
摘要:二分法O(nlogn) class Solution { public: int bSearch(vector<int>& numbers, int left, int right, int target){ // 左闭右开 找左侧边界 while(left < right){ int mid = 阅读全文
posted @ 2022-02-28 20:02 fwx 阅读(20) 评论(0) 推荐(0) 编辑
摘要:主要是partition函数的书写,其中两个while循环的顺序改变了会出错。 class Solution { public: int patition(vector<int>& nums, int left, int right){ int i = left, j = right; int te 阅读全文
posted @ 2022-02-28 19:58 fwx 阅读(32) 评论(0) 推荐(0) 编辑
摘要:需要记录两类值即可,一个是每个节点向左最多能到的节点数,一个是每个节点向右最多能到的节点数,并通过dfs来搜索即可。 class Solution { public: vector<int> *record_left; vector<int> *record_right; const int LEF 阅读全文
posted @ 2022-02-28 19:56 fwx 阅读(20) 评论(0) 推荐(0) 编辑
摘要:1. 基本型: 因为我们初始化 right = nums.length - 1 所以决定了我们的「搜索区间」是 [left, right] 所以决定了 while (left <= right) 同时也决定了 left = mid+1 和 right = mid-1 因为我们只需找到一个 targe 阅读全文
posted @ 2022-02-28 19:50 fwx 阅读(28) 评论(2) 推荐(0) 编辑

点击右上角即可分享
微信分享提示