04 2020 档案
常用数据结构
摘要:string: string substr(int pos , int n) ; int find(string s , int pos) ; int find(char c , int pos) ; int find_first_of(strng s , int pos) ;int find_fi 阅读全文
posted @ 2020-04-13 11:35 景行cmy 阅读(112) 评论(0) 推荐(0)
topk 问题
摘要:对于固定数量的数据,堆排序和快速排序都可以,数据流就用堆排序 //堆排序: class Solution { int findKthLargest(int k , vector<int>& nums) { priority_queue<int,vector<int>,greater<int>> p 阅读全文
posted @ 2020-04-12 13:59 景行cmy 阅读(107) 评论(0) 推荐(0)
leetcode 5. Longest Palindromic Substring
摘要:题目:Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000. 题目解析:做题一定不要陷入惯性思维,要注重审题,从题目出发。不 阅读全文
posted @ 2020-04-10 10:13 景行cmy 阅读(85) 评论(0) 推荐(0)
leetcode 1000. Minimum Cost to Merge Stones
摘要:There are N piles of stones arranged in a row. The i-th pile has stones[i] stones. A move consists of merging exactly K consecutive piles into one pil 阅读全文
posted @ 2020-04-07 13:26 景行cmy 阅读(114) 评论(0) 推荐(0)
leetcode 695. Max Area of Island
摘要:题目解析:找到最大连通块。并查集模板题。 class Solution { public: int maxAreaOfIsland(vector<vector<int>>& grid) { if(grid.empty()) return 0 ; int m = grid.size() , n = g 阅读全文
posted @ 2020-04-05 11:45 景行cmy 阅读(137) 评论(0) 推荐(0)
排序总结
摘要:稳定性排序:稳定性排序是指相等的元素相对位置不会发生改变。 以下介绍一系列排序算法:以非降序排列为序; 选择排序:遍历i,求[i,n)中的最小值,与A[i]交换; 时间复杂度O(N^2) void selection_sort(vector<int>& num) { int len = num.si 阅读全文
posted @ 2020-04-05 10:31 景行cmy 阅读(190) 评论(0) 推荐(0)
leetcode rotated sorted array
摘要:leeetcode 33. Search in Rotated Sorted Array leetcode 81 leetcode 153. Find Minimum in Rotated Sorted Array 这几道的相似处是:都是部分有序的数组,可以用二分搜索来做。最重要的是判断到底是左区间 阅读全文
posted @ 2020-04-04 08:01 景行cmy 阅读(127) 评论(0) 推荐(0)
leetcode 33. Search in Rotated Sorted Array
摘要:https://leetcode.com/problems/search-in-rotated-sorted-array/ 解法一:本来有序的数组经过rotate后,分成了两部分。以最大值为分割点。通过二分搜索找最大值。然后在[0 , maxi] , 和[maxi + 1 , nums.size() 阅读全文
posted @ 2020-04-03 23:02 景行cmy 阅读(123) 评论(0) 推荐(0)
leetcode 103. Binary Tree Zigzag Level Order Traversal
摘要:https://leetcode.com/problems/binary-tree-zigzag-level-order-traversal/ 题目解析:zigzag遍历就是上一次遍历的最后一个节点的最后一个子节点就是下一次遍历的第一个节点,如果是从左往右遍历,最后一个子节点就是最后一个节点的右节点 阅读全文
posted @ 2020-04-03 21:35 景行cmy 阅读(115) 评论(0) 推荐(0)