摘要:
substr有2种用法:假设:string s = “012345”; string sub1 = s.substr(2); //只有一个数字5表示从下标为5开始一直到结尾:sub1 = “2345” string sub2 = s.substr(2, 2); //从下标为5开始截取长度为3位:su 阅读全文
摘要:
struct TreeNode { int val; TreeNode *left; TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) {} }; class Solution {public: vector<vec 阅读全文
摘要:
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 阅读全文
摘要:
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 阅读全文
摘要:
方法1(引入unordermap进行迭代判断): class Solution {public: int searchInsert(vector<int>& nums, int target) { if(nums.size()==0) { return -1; } unordered_map<int 阅读全文
摘要:
#include<iostream> struct TreeNode { int val; TreeNode *left; TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) {} }; class Solution 阅读全文
摘要:
代码: #include<iostream>#include<vector>using namespace std; class Solution {public: //一遍数组遍历 int findMin(vector<int>& nums) { int min=nums[0]; int nums 阅读全文
摘要:
转载:https://www.cnblogs.com/xylc/p/3653036.html 随着C++11标准的出现,C++标准添加了许多有用的特性,C++代码的写法也有比较多的变化。 vector是经常要使用到的std组件,对于vector的遍历,本文罗列了若干种写法。 (注:本文中代码为C++ 阅读全文
摘要:
方法1:迭代法 代码: #include<iostream>using namespace std; struct ListNode { int val; ListNode *next; ListNode(int x) : val(x), next(NULL) {} }; class Solutio 阅读全文
摘要:
#include<iostream> struct ListNode { int val; ListNode *next; ListNode(int x) : val(x), next(NULL) {} }; class Solution {public: ListNode* deleteNode( 阅读全文