摘要: 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 诗和远方* 阅读(449) 评论(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 诗和远方* 阅读(660) 评论(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 诗和远方* 阅读(175) 评论(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 诗和远方* 阅读(230) 评论(0) 推荐(0) 编辑