摘要: ``` void sort_merge(vector &v,int left,int right) { if(left =right) return; int mid=(left+right)/2; sort_merge(v,left,mid); sort_merge(v,mid+1,right); 阅读全文
posted @ 2019-04-10 17:08 JohnRed 阅读(161) 评论(0) 推荐(0)
摘要: ``` void sort_quick(vector &v,int left,int right) { if(left =right) return; int tmp=v[left]; int i=left,j=right; while(i!=j) { while(itmp) j ; if(i 阅读全文
posted @ 2019-04-10 16:08 JohnRed 阅读(377) 评论(0) 推荐(0)
摘要: ``` void sort_bubble(vector &v) { for(int i=v.size()-1;i>0;i--) { for(int j=0;jv[j+1]) { int tmp=v[j]; v[j]=v[j+1]; v[j+1]=tmp; } } } } ``` 阅读全文
posted @ 2019-04-10 15:46 JohnRed 阅读(278) 评论(0) 推荐(0)
摘要: ``` void sort_insertion(vector &v) { for(int i=1;i0;j ) { if(v[j] 阅读全文
posted @ 2019-04-10 15:31 JohnRed 阅读(122) 评论(0) 推荐(0)
摘要: ``` class Solution { public: int maximumGap(vector &numss) { if (numss.empty()) return 0; int mx = INT_MIN, mn = INT_MAX, n = numss.size(); for (int d 阅读全文
posted @ 2019-04-10 14:10 JohnRed 阅读(81) 评论(0) 推荐(0)
摘要: ``` class Solution { public: vector findMissingRanges(vector& nums, int lower, int upper) { vector res; int l = lower; for (int i = 0; i l) { res.push_back... 阅读全文
posted @ 2019-04-10 12:11 JohnRed 阅读(114) 评论(0) 推荐(0)
摘要: ``` class Solution { public: int findPeakElement(vector& nums) { for (int i = 1; i 阅读全文
posted @ 2019-04-10 11:05 JohnRed 阅读(91) 评论(0) 推荐(0)
摘要: ``` class Solution { public: bool isOneEditDistance(string s, string t) { if (s.size() = 2) return false; else if (diff == 1) { for (int i = 0; i 阅读全文
posted @ 2019-04-10 11:04 JohnRed 阅读(124) 评论(0) 推荐(0)
摘要: ``` class Solution { public: ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) { if (!headA || !headB) return NULL; ListNode *a = headA, *b = headB; while (a ... 阅读全文
posted @ 2019-04-10 11:02 JohnRed 阅读(91) 评论(0) 推荐(0)
摘要: ``` class Solution { public: int lengthOfLongestSubstringTwoDistinct(string s) { int res = 0, left = 0; unordered_map m; for (int i = 0; i 2) { if (--m[s[l... 阅读全文
posted @ 2019-04-10 11:01 JohnRed 阅读(69) 评论(0) 推荐(0)
摘要: ``` // Recursion class Solution { public: TreeNode *upsideDownBinaryTree(TreeNode *root) { if (!root || !root->left) return root; TreeNode *l = root->left, *r = root->right; ... 阅读全文
posted @ 2019-04-10 10:59 JohnRed 阅读(100) 评论(0) 推荐(0)
摘要: ``` class MinStack { public: /** initialize your data structure here. */ MinStack() {} void push(int x) { s1.push(x); if (s2.empty() || x s1, s2; }; ``` 阅读全文
posted @ 2019-04-10 10:57 JohnRed 阅读(77) 评论(0) 推荐(0)
摘要: ``` class Solution { public: int findMin(vector &nums) { if (nums.empty()) return 0; int left = 0, right = nums.size() - 1, res = nums[0]; while (left nums[mid]) { ... 阅读全文
posted @ 2019-04-10 10:56 JohnRed 阅读(53) 评论(0) 推荐(0)
摘要: ``` class Solution { public: int findMin(vector &num) { int left = 0, right = num.size() 1; if (num[left] num[right]) { while (left != (right 1)) { in 阅读全文
posted @ 2019-04-10 10:55 JohnRed 阅读(66) 评论(0) 推荐(0)
摘要: ``` class Solution { public: int maxProduct(vector& nums) { if (nums.empty()) return 0; int res = nums[0], mn = nums[0], mx = nums[0]; for (int i = 1; 阅读全文
posted @ 2019-04-10 10:53 JohnRed 阅读(64) 评论(0) 推荐(0)
摘要: ``` class Solution { public: /** * @param s : A string * @return : A string */ string reverseWords(string s) { istringstream is(s); is >> s; string t; ... 阅读全文
posted @ 2019-04-10 10:50 JohnRed 阅读(87) 评论(0) 推荐(0)
摘要: ``` class Solution { public: int evalRPN(vector &tokens) { // IMPORTANT: Please reset any member data you declared, as // the same Solution instance w 阅读全文
posted @ 2019-04-10 10:49 JohnRed 阅读(74) 评论(0) 推荐(0)
摘要: ``` class Solution { public: int maxPoints(vector& points) { int res = 0; for (int i = 0; i , int> m; int duplicate = 1; for (int j = i + 1; j second + dupl... 阅读全文
posted @ 2019-04-10 10:48 JohnRed 阅读(66) 评论(0) 推荐(0)
摘要: ``` class Solution { public: ListNode* sortList(ListNode* head) { if (!head || !head->next) return head; ListNode *slow = head, *fast = head, *pre = head; while (fast && fa... 阅读全文
posted @ 2019-04-10 10:45 JohnRed 阅读(104) 评论(0) 推荐(0)
摘要: ``` class Solution { public: ListNode* insertionSortList(ListNode* head) { ListNode *dummy = new ListNode(-1), *cur = dummy; while (head) { ListNode *t = head->next; ... 阅读全文
posted @ 2019-04-10 10:39 JohnRed 阅读(66) 评论(0) 推荐(0)