题目: 解答: 1 class Solution { 2 public: 3 void merge(vector<int>& A, int m, vector<int>& B, int n) 4 { 5 int len1 = m - 1; 6 int len2 = n - 1; 7 int len ...
分类:
编程语言 时间:
2020-05-05 20:13:16
阅读次数:
67
题目: 解答: 先排序,然后设定返回值为最大,用双指针求得结果。 1 class Solution { 2 public: 3 int smallestDifference(vector<int>& a, vector<int>& b) 4 { 5 sort(a.begin(),a.end()); ...
分类:
编程语言 时间:
2020-05-05 20:11:14
阅读次数:
61
题目: 解答: 方法一:会超时间 1 class Solution { 2 public: 3 void rotate(vector<vector<int>>& matrix) 4 { 5 // 思路是: 转置 + 反转每一行 6 7 int len = matrix.size(); 8 9 // ...
分类:
编程语言 时间:
2020-05-05 20:09:54
阅读次数:
66
题目: 解答: 1 class Solution { 2 public: 3 vector<vector<int>> res; 4 5 vector<vector<int>> subsets(vector<int>& nums) 6 { 7 // 记录走过的路径 8 vector<int> trac ...
分类:
编程语言 时间:
2020-05-05 19:54:39
阅读次数:
60
1 class Solution 2 { 3 public: 4 int maxProfit(vector<int>& prices, int fee) 5 { 6 int n = prices.size(); 7 vector<vector<int>> dp(n,vector<int>(2,0)) ...
分类:
其他好文 时间:
2020-05-05 19:52:50
阅读次数:
93
1 class Solution 2 { 3 public: 4 int maxProfit(vector<int>& prices) 5 { 6 if(prices.size() < 2) return 0; 7 int n = prices.size(); 8 vector<vector<int ...
分类:
其他好文 时间:
2020-05-05 19:46:36
阅读次数:
45
1 // 一次交易由买入和卖出构成,至少需要两天。所以说有效的限制 k 应该不超过 n/2,如果超过,就没有约束作用了,相当于 k = +infinity。 2 class Solution 3 { 4 public: 5 int maxProfit(int K, vector<int>& pric ...
分类:
其他好文 时间:
2020-05-05 19:43:25
阅读次数:
60
题目: 解答: 1 class Solution { 2 public: 3 int numSubarrayProductLessThanK(vector<int>& nums, int k) 4 { 5 if (k <= 1) 6 { 7 return 0; 8 } 9 10 int prod = ...
分类:
编程语言 时间:
2020-05-05 18:13:01
阅读次数:
56
题目: 解答: 1 class Solution { 2 public: 3 vector<int> productExceptSelf(vector<int>& nums) 4 { 5 int n = nums.size(); 6 7 //把向量output初始化为1 8 vector<int> ...
分类:
编程语言 时间:
2020-05-05 18:04:21
阅读次数:
56
题目: 解答: 就很简单的遍历一遍...中间判断数字是否连续。 1 class Solution { 2 public: 3 vector<string> summaryRanges(vector<int>& nums) 4 { 5 vector<string> ans; 6 for(int i = ...
分类:
编程语言 时间:
2020-05-05 18:02:35
阅读次数:
60