上一页 1 ··· 4 5 6 7 8 9 下一页
摘要: 204. 计数质数 vector<int> getPrimes(int n) { vector<int> primes; vector<int> isPrimes(n, 1); for (int i = 2; i < n; ++i) { if (isPrimes[i]) { primes.empla 阅读全文
posted @ 2020-12-03 10:54 miyanyan 阅读(55) 评论(0) 推荐(0) 编辑
摘要: lexicographical_compare - C++ Reference Returns true if the range [first1,last1) compares lexicographically less than the range [first2,last2). 阅读全文
posted @ 2020-12-02 14:37 miyanyan 阅读(54) 评论(0) 推荐(0) 编辑
摘要: 排序这篇是数组排序,刷leetcode的时候碰到了链表排序,记录一下。 ####插入排序 class Solution { public: ListNode* insertionSortList(ListNode* head) { if(!head) return nullptr; ListNode 阅读全文
posted @ 2020-11-21 17:35 miyanyan 阅读(179) 评论(0) 推荐(0) 编辑
摘要: b站视频 : 【ACM】树状数组与ST表 int a[10005]; int c[10005]; int n; int lowbit(int x){ return x&(-x); } int getSum(int x){ int ans = 0; while(x > 0){ ans += c[x]; 阅读全文
posted @ 2020-11-16 13:58 miyanyan 阅读(43) 评论(0) 推荐(0) 编辑
摘要: ###463. 岛屿的周长 每有一个位置是1,则周长+4 如果上一个是1,则公用上边,周长-2;如果左一个是1,则公用左边,周长-2 class Solution { public: int islandPerimeter(vector<vector<int>>& grid) { int n = g 阅读全文
posted @ 2020-10-30 11:16 miyanyan 阅读(154) 评论(0) 推荐(0) 编辑
摘要: ###冒泡排序(bubble sort) 冒泡排序只会操作相邻的两个数据。每次冒泡操作都会对相邻的两个元素进行比较,看是否满足大小关系要求。如果不满足就让它俩互换。一次冒泡会让至少一个元素移动到它应该在的位置,重复 n 次,就完成了 n 个数据的排序工作。 冒泡排序还可以优化,比如本来要外循环6次, 阅读全文
posted @ 2020-10-28 22:04 miyanyan 阅读(146) 评论(0) 推荐(0) 编辑
摘要: Leetcode51. N 皇后 Leetcode52. N皇后 II ####示例 输入:4 输出:[ [".Q..", // 解法 1 "...Q", "Q...", "..Q."], ["..Q.", // 解法 2 "Q...", "...Q", ".Q.."] ] 解释: 4 皇后问题存在 阅读全文
posted @ 2020-10-19 19:31 miyanyan 阅读(81) 评论(0) 推荐(0) 编辑
摘要: ###正常求幂 PS:先不考虑异常输入, int溢出 int normalPow(int x, int n){ int res = 1; while(n){ res *= x; n --; } return res; } 问题: n值小的时候计算量可以接受,一旦大了,计算量非常大,于是要将这个O(n 阅读全文
posted @ 2020-10-12 18:19 miyanyan 阅读(56) 评论(0) 推荐(0) 编辑
摘要: ###反转链表示例: 输入: 1->2->3->4->5->NULL 输出: 5->4->3->2->1->NULL ####思路 备份 旧head->next head->next更新为新节点 head 变为 旧head->next class Solution { public: ListNod 阅读全文
posted @ 2020-10-11 20:09 miyanyan 阅读(168) 评论(0) 推荐(0) 编辑
摘要: ###二分查找是建立在有序的基础上的 ###基础模板 int bsearch(vector<int>& numbers, int value) { int left=0, right = numbers.size()-1; while(left <= right){ //有的写法这里是 < , 则条 阅读全文
posted @ 2020-10-10 15:41 miyanyan 阅读(85) 评论(0) 推荐(0) 编辑
上一页 1 ··· 4 5 6 7 8 9 下一页