摘要: 动态规划 time O class Solution { public: int maxCoins(vector<int>& nums) { nums.insert(nums.begin(),1); nums.push_back(1); int n=nums.size(); vector<vecto 阅读全文
posted @ 2019-12-09 22:36 Joel_Wang 阅读(322) 评论(0) 推荐(0) 编辑
摘要: 这道题第一思路是用二分查找 因为使用二分法:所以复杂度为O(n*logk), k介于 left=sum/threshold(向下取整) 和 right=num_max之间;而right<=10^6, left>=1; 故logk <=6log2(10) ~=18; 主要是估算可能除数的上下界,上面的 阅读全文
posted @ 2019-12-09 10:16 Joel_Wang 阅读(317) 评论(0) 推荐(0) 编辑
摘要: 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) 编辑