码迷,mamicode.com
首页 >  
搜索关键字:解答    ( 4882个结果
【数组】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
【数组】442. 数组中重复的数据
题目: 解答: 利用题目中所给信息 1 ≤ a[i] ≤ n ,将出现过的数字作为数组的index(访问元素时需要减一),如果出现一次的,将该index下的数取相反数,记录此时的状态,如果值为index的数字再出现一次(此时index索引的值为负数),那么这个数字就出现了两次。 比如 数组 [2,2 ...
分类:编程语言   时间:2020-05-05 17:58:46    阅读次数:53
【数组】581. 最短无序连续子数组
题目: 解答: 单调栈 正向遍历,单调递增栈,找出自始至终没有出栈的最大索引 l 反向遍历,单调递减栈,找出自始至终没有出栈的最小索引 r 中间就是需要排序的最小子数组 1 class Solution { 2 public: 3 int findUnsortedSubarray(vector<in ...
分类:编程语言   时间:2020-05-05 17:49:42    阅读次数:56
【数组】380. 常数时间插入、删除和获取随机元素
题目: 解答: 此题的正确解法是利用到了一个一维数组和一个 HashMap,其中数组用来保存数字,HashMap 用来建立每个数字和其在数组中的位置之间的映射。 插入操作——先看这个数字是否已经在 HashMap 中存在,如果存在的话直接返回 false,不存在的话,将其插入到数组的末尾,然后建立数 ...
分类:编程语言   时间:2020-05-05 17:38:33    阅读次数:80
【数组】41. 缺失的第一个正数
题目: 解答: 方法一: 方法二: 方法三 : 1 class Solution { 2 public: 3 int firstMissingPositive(vector<int>& nums) 4 { 5 for (int i = 0; i < nums.size(); i++) 6 { 7 w ...
分类:编程语言   时间:2020-05-05 15:14:03    阅读次数:65
【二分查找】35. 搜索插入位置
题目: 解答: 1 class Solution { 2 public: 3 int searchInsert(vector<int> &nums, int target) 4 { 5 int left = 0; 6 int right = nums.size() - 1; 7 8 while(le ...
分类:其他好文   时间:2020-05-05 12:40:50    阅读次数:49
【二分查找】74. 搜索二维矩阵
题目: 解答: 按杨氏矩阵的方法求解,时间复杂度为O(m+n),其中m为矩阵的行数,n为矩阵的列数。 1 class Solution { 2 public: 3 bool searchMatrix(vector<vector<int>>& matrix, int target) 4 { 5 if( ...
分类:其他好文   时间:2020-05-05 12:37:47    阅读次数:47
【二分查找】33. 搜索旋转排序数组
题目: 解答: 1 class Solution { 2 public: 3 int search(vector<int>& nums, int target) 4 { 5 int l = 0; 6 int r = nums.size() -1; 7 8 while (l <= r) 9 { 10 ...
分类:编程语言   时间:2020-05-05 12:36:15    阅读次数:57
【数组】977. 有序数组的平方
题目: 解答: lef和rig分别指向左右的数,比较并从最大位开始装。 1 class Solution { 2 public: 3 vector<int> sortedSquares(vector<int>& A) 4 { 5 int len = A.size(); 6 vector<int> a ...
分类:编程语言   时间:2020-05-04 19:50:58    阅读次数:59
4882条   上一页 1 ... 25 26 27 28 29 ... 489 下一页
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!