上一页 1 2 3 4 5 6 ··· 23 下一页
摘要: class Solution { public: vector<vector<int>> groupThePeople(vector<int>& groupSizes) { map<int, vector<int> > m;//每个size组包含的元素 set<int> s;//记录用户组的size 阅读全文
posted @ 2019-12-09 10:12 Joel_Wang 阅读(330) 评论(0) 推荐(0) 编辑
摘要: class Solution { public: int subtractProductAndSum(int n) { int add=0; int prod=1; while(n>0){ int r=n%10; n/=10; prod*=r; add+=r; } int res=prod-add; 阅读全文
posted @ 2019-12-09 10:10 Joel_Wang 阅读(216) 评论(0) 推荐(0) 编辑
摘要: class Solution { public: int numSquares(int n) { //初始化vector<int> dp[i]=i i=[0,n]; //状态转移方程 dp[i]=min(dp[i],dp[i-j*j]+1) i-j*j>=0 && j=0, j++; //time 阅读全文
posted @ 2019-12-06 20:18 Joel_Wang 阅读(248) 评论(0) 推荐(0) 编辑
摘要: 答案参考:https://www.zhihu.com/people/cxyxiaowu/activities time O(n) space O(1): 双指针法,计算的中心思想为: 左右(包括自身)最低的柱子决定能装多少水,装水的体积为 water_i = min { l_max, r_max } 阅读全文
posted @ 2019-12-05 20:51 Joel_Wang 阅读(161) 评论(0) 推荐(0) 编辑
摘要: time O(n^2*k) space O(n^2) class Solution { public: int palindromePartition(string s, int K) { //分成两步:第一步递归求将下标【i,j】变为回文子串的最小代价cost(i,j); //cost(i,j)= 阅读全文
posted @ 2019-12-05 17:24 Joel_Wang 阅读(267) 评论(0) 推荐(0) 编辑
摘要: a:excellent几乎一次ac或只有点小bug很快解决;半年后再重刷; b:经过艰难的debug和磕磕绊绊或者看了小提示才刷出来; c:经过艰难的debug没做出来,看答案刷的; 艾宾浩斯遗忘曲线数列:1,2,4,7,15,31 当天做的题目为0,将标注1 2 4 7 的题目做一遍,每天 1(n 阅读全文
posted @ 2019-12-04 13:50 Joel_Wang 阅读(316) 评论(0) 推荐(0) 编辑
摘要: 排序后取数组第k个元素,遍历需要n^2的复杂度,查找插入logn,时间复杂度O(n^2logn)。方法很笨,完全就是STL过于牛x运行通过的。 class Solution { public: int kthSmallest(vector<vector<int>>& matrix, int k) { 阅读全文
posted @ 2019-12-04 10:19 Joel_Wang 阅读(162) 评论(0) 推荐(0) 编辑
摘要: 1. 首先考虑排序后交替插入 首尾交替插入,这种方法对于有重复数字的数组不可行; class Solution { public: void wiggleSort(vector<int>& nums) { //因为一定存在最优解,所以一定可行的方法就是先排序,然后将最小的数逐渐插入到最大里面; // 阅读全文
posted @ 2019-12-02 11:34 Joel_Wang 阅读(292) 评论(0) 推荐(0) 编辑
摘要: class Solution { public: vector<vector<string>> ans; bool isok(string s){ int i=0; int j=s.size()-1; while(i<j){ if(s[i]!=s[j]){ return false; } i++;j 阅读全文
posted @ 2019-11-29 11:57 Joel_Wang 阅读(149) 评论(0) 推荐(0) 编辑
摘要: 1. 采用归并排序计算逆序数组对的方法来计算右侧更小的元素 time O(nlogn); 计算逆序对可以采用两种思路: a. 在左有序数组元素出列时计算右侧比该元素小的数字的数目为 cnt=r-mid-1; 右有序数组出列完成后cnt=end-mid; b. 在右有序数组元素出列时计算左侧比该元素大 阅读全文
posted @ 2019-11-20 12:09 Joel_Wang 阅读(350) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 ··· 23 下一页