随笔分类 - 《剑指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--;//倒序删除第二段元
阅读全文
摘要:无语,就是两个栈倒来倒去 class MyQueue { public: stack<int> st; stack<int> tmp; /** Initialize your data structure here. */ MyQueue() { } /** Push element x to th
阅读全文
摘要: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;
阅读全文
摘要: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
阅读全文
摘要: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
阅读全文
摘要: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) //防止遇到重复
阅读全文
摘要:/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), r
阅读全文
摘要:/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode *father; * TreeNode(int x) : v
阅读全文