上一页 1 2 3 4 5 6 7 8 ··· 13 下一页
摘要: substr有2种用法:假设:string s = “012345”; string sub1 = s.substr(2); //只有一个数字5表示从下标为5开始一直到结尾:sub1 = “2345” string sub2 = s.substr(2, 2); //从下标为5开始截取长度为3位:su 阅读全文
posted @ 2020-11-04 10:15 诗和远方* 阅读(1531) 评论(0) 推荐(0) 编辑
摘要: struct TreeNode { int val; TreeNode *left; TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) {} }; class Solution {public: vector<vec 阅读全文
posted @ 2020-11-03 21:17 诗和远方* 阅读(444) 评论(0) 推荐(0) 编辑
摘要: class Solution {public: vector<int>v1 = {-1,-1}; vector<int> searchRange(vector<int>& nums, int target) { if(nums.size()==0) { return v1; } v1[0] = fi 阅读全文
posted @ 2020-11-03 17:55 诗和远方* 阅读(640) 评论(0) 推荐(0) 编辑
摘要: class Solution { public: int peakIndexInMountainArray(vector<int>& arr) { int n = arr.size(); if(n==0) { return -1; } int left = 0; int right = n-1; w 阅读全文
posted @ 2020-11-03 12:32 诗和远方* 阅读(172) 评论(0) 推荐(0) 编辑
摘要: 方法1(引入unordermap进行迭代判断): class Solution {public: int searchInsert(vector<int>& nums, int target) { if(nums.size()==0) { return -1; } unordered_map<int 阅读全文
posted @ 2020-11-03 10:27 诗和远方* 阅读(223) 评论(0) 推荐(0) 编辑
摘要: #include<iostream> struct TreeNode { int val; TreeNode *left; TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) {} }; class Solution 阅读全文
posted @ 2020-11-02 12:04 诗和远方* 阅读(425) 评论(0) 推荐(0) 编辑
摘要: 代码: #include<iostream>#include<vector>using namespace std; class Solution {public: //一遍数组遍历 int findMin(vector<int>& nums) { int min=nums[0]; int nums 阅读全文
posted @ 2020-10-30 12:00 诗和远方* 阅读(89) 评论(0) 推荐(0) 编辑
摘要: 转载:https://www.cnblogs.com/xylc/p/3653036.html 随着C++11标准的出现,C++标准添加了许多有用的特性,C++代码的写法也有比较多的变化。 vector是经常要使用到的std组件,对于vector的遍历,本文罗列了若干种写法。 (注:本文中代码为C++ 阅读全文
posted @ 2020-10-29 17:59 诗和远方* 阅读(658) 评论(0) 推荐(0) 编辑
摘要: 方法1:迭代法 代码: #include<iostream>using namespace std; struct ListNode { int val; ListNode *next; ListNode(int x) : val(x), next(NULL) {} }; class Solutio 阅读全文
posted @ 2020-10-28 20:19 诗和远方* 阅读(177) 评论(0) 推荐(0) 编辑
摘要: #include<iostream> struct ListNode { int val; ListNode *next; ListNode(int x) : val(x), next(NULL) {} }; class Solution {public: ListNode* deleteNode( 阅读全文
posted @ 2020-10-28 11:25 诗和远方* 阅读(105) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 8 ··· 13 下一页