上一页 1 2 3 4 5 6 ··· 14 下一页
摘要: 双指针 对于一个序列,用两个指针维护一段区间; 对于两个序列,维护某种次序,比如归并排序中合并两个有序序列的操作; for(int i = 0, j = 0; j < n; j++) { //当前维护的区间不满足条件,i向前移动到满足条件 while(i < j && check(i, j)) i+ 阅读全文 »
posted @ 2020-08-23 16:56 NaughtyCoder 阅读(113) 评论(0) 推荐(0)
摘要: 在排序数组中查找数字 题目链接:https://leetcode-cn.com/problems/zai-pai-xu-shu-zu-zhong-cha-zhao-shu-zi-lcof/ class Solution { public: int search(vector<int>& nums, 阅读全文 »
posted @ 2020-08-23 15:03 NaughtyCoder 阅读(112) 评论(0) 推荐(0)
摘要: 找精确值模板 int l = 0, r = n - 1; while(l <= r) { int mid = l + r >> 1; if(arr[mid] == target) return mid; else if(arr[mid] > target) r = mid - 1; else l = 阅读全文 »
posted @ 2020-08-22 22:58 NaughtyCoder 阅读(111) 评论(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 阅读(100) 评论(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 阅读(71) 评论(0) 推荐(0)
摘要: 0-1背包 题目链接:https://www.acwing.com/problem/content/2/ 思路 实现 #include <iostream> using namespace std; const int N = 1010; int dp[N][N]; int V[N]; int W[ 阅读全文 »
posted @ 2020-08-20 11:36 NaughtyCoder 阅读(84) 评论(0) 推荐(0)
摘要: 题目链接:https://leetcode-cn.com/problems/subarray-sum-equals-k/ 前缀和 + 枚举 class Solution { public: int subarraySum(vector<int>& nums, int k) { int n = num 阅读全文 »
posted @ 2020-08-20 10:41 NaughtyCoder 阅读(80) 评论(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 阅读(62) 评论(0) 推荐(0)
摘要: 无向图中连通分量的数目 题目链接: https://leetcode-cn.com/problems/number-of-connected-components-in-an-undirected-graph/ class Solution { public: vector<int> parent; 阅读全文 »
posted @ 2020-08-17 14:54 NaughtyCoder 阅读(140) 评论(0) 推荐(0)
摘要: 并查集 将两个集合合并; 询问两个元素是否在一个集合当中; 基本原理:每个集合用一颗树来维护,每个集合根节点的编号是当前集合的编号,每个节点存储它的父节点,p 表示x的父节点; 如何判断树根: p[x] = x; 查找:如何求x的集合编号: 想判断某个点属于哪个集合,找到它所在的树的树根; whil 阅读全文 »
posted @ 2020-08-17 14:22 NaughtyCoder 阅读(88) 评论(0) 推荐(0)
上一页 1 2 3 4 5 6 ··· 14 下一页
点击右上角即可分享
微信分享提示