码迷,mamicode.com
首页 >  
搜索关键字:vector    ( 11651个结果
【数组】面试题 10.01. 合并排序的数组
题目: 解答: 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
【数组】面试题 16.06. 最小差
题目: 解答: 先排序,然后设定返回值为最大,用双指针求得结果。 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
【数组】面试题 01.07. 旋转矩阵
题目: 解答: 方法一:会超时间 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
【数组】面试题 08.04. 幂集
题目: 解答: 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
714. 买卖股票的最佳时机含手续费
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
309. 最佳买卖股票时机含冷冻期
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
188. 买卖股票的最佳时机 IV
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
【数组】713. 乘积小于K的子数组
题目: 解答: 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
【数组】238. 除自身以外数组的乘积
题目: 解答: 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
【数组】228. 汇总区间
题目: 解答: 就很简单的遍历一遍...中间判断数字是否连续。 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
11651条   上一页 1 ... 71 72 73 74 75 ... 1166 下一页
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!