随笔分类 -  《剑指offer》

摘要:class Solution { public: int findMin(vector<int>& nums) { if(!nums.size()) return -1; int n=nums.size()-1; while(n>0&&nums[n]==nums[0]) n--;//倒序删除第二段元 阅读全文
posted @ 2023-03-15 14:16 穿过雾的阴霾 阅读(14) 评论(0) 推荐(0) 编辑
摘要:无语,就是两个栈倒来倒去 class MyQueue { public: stack<int> st; stack<int> tmp; /** Initialize your data structure here. */ MyQueue() { } /** Push element x to th 阅读全文
posted @ 2023-03-14 15:36 穿过雾的阴霾 阅读(7) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: string replaceSpaces(string &str) { int len=0; for(auto c:str) { if(c==' ') len+=3; else len++; } int i=str.size()-1,j=len-1; 阅读全文
posted @ 2023-03-13 10:53 穿过雾的阴霾 阅读(13) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: bool searchArray(vector<vector<int>> array, int target) { if(array.empty()||array[0].empty()) return false; int i=0,j=array[0 阅读全文
posted @ 2023-03-13 10:51 穿过雾的阴霾 阅读(10) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: int duplicateInArray(vector<int>& nums) { int l=1,r=nums.size()-1;//注意r是n-1 while(l<r) { int cnt=0;//记录≤mid的个数 int mid=l+r>>1 阅读全文
posted @ 2023-03-13 10:51 穿过雾的阴霾 阅读(16) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: int duplicateInArray(vector<int>& nums) { int n=nums.size(); for (int i = 0; i < n; i ++ ) if(nums[i]<0||nums[i]>=n) //防止遇到重复 阅读全文
posted @ 2023-03-13 10:50 穿过雾的阴霾 阅读(16) 评论(0) 推荐(0) 编辑
摘要:/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), r 阅读全文
posted @ 2023-03-13 10:49 穿过雾的阴霾 阅读(11) 评论(0) 推荐(0) 编辑
摘要:/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode *father; * TreeNode(int x) : v 阅读全文
posted @ 2023-03-13 10:48 穿过雾的阴霾 阅读(14) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示