码迷,mamicode.com
首页 >  
搜索关键字:vector    ( 11651个结果
剑指offer——和为s的连续正整数序列
输入一个正整数 target ,输出所有和为 target 的连续正整数序列(至少含有两个数)。 序列内的数字由小到大排列,不同序列按照首个数字从小到大排列。 示例 1: 输入:target = 9输出:[[2,3,4],[4,5]]示例 2: 输入:target = 15输出:[[1,2,3,4, ...
分类:其他好文   时间:2020-05-05 18:02:16    阅读次数:85
【数组】581. 最短无序连续子数组
题目: 解答: 单调栈 正向遍历,单调递增栈,找出自始至终没有出栈的最大索引 l 反向遍历,单调递减栈,找出自始至终没有出栈的最小索引 r 中间就是需要排序的最小子数组 1 class Solution { 2 public: 3 int findUnsortedSubarray(vector<in ...
分类:编程语言   时间:2020-05-05 17:49:42    阅读次数:56
数岛屿
47个用例过了42 ,用了一个图色彩的方法,标记图书,然后调过,调用栈过长,肯能要优化一下 附录GDB 调试的源码 #include <vector> #include<iostream> using namespace std; class Solution { bool Inmap(int i ...
分类:其他好文   时间:2020-05-05 17:43:17    阅读次数:72
【数组】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
C++结构体排序
我将结构体 $result$ 存入在一个vector ${vResult}$ 中,最近需要在C++中按照结构体中的 $score$ 进行排序,在网上查找了一些资料,这里对采用的方法记录一下,方便以后使用。 一、引入头文件 #include <algorithm> 二、定义排序方法 struct re ...
分类:编程语言   时间:2020-05-05 12:23:03    阅读次数:63
leetcode 140 Word Break II
leetcode 139 word break class Solution { public: bool wordBreak(string s, vector<string>& wordDict) { unordered_set<string> wordset(wordDict.begin(),w ...
分类:其他好文   时间:2020-05-05 11:04:03    阅读次数:59
300. 最长上升子序列
题目描述: 给定一个无序的整数数组,找到其中最长上升子序列的长度。 示例: 输入: [10,9,2,5,3,7,101,18]输出: 4 解释: 最长的上升子序列是 [2,3,7,101],它的长度是 4。说明: 可能会有多种最长上升子序列的组合,你只需要输出对应的长度即可。你算法的时间复杂度应该为 ...
分类:其他好文   时间:2020-05-05 10:45:49    阅读次数:50
11651条   上一页 1 ... 72 73 74 75 76 ... 1166 下一页
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!