摘要:
``` 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
阅读(165)
评论(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
阅读(379)
评论(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
阅读(280)
评论(0)
推荐(0)
摘要:
``` void sort_insertion(vector &v) { for(int i=1;i0;j ) { if(v[j] 阅读全文
posted @ 2019-04-10 15:31
JohnRed
阅读(124)
评论(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
阅读(82)
评论(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
阅读(115)
评论(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
阅读(125)
评论(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
阅读(92)
评论(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
阅读(72)
评论(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
阅读(101)
评论(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
阅读(79)
评论(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
阅读(55)
评论(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
阅读(69)
评论(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
阅读(65)
评论(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
阅读(77)
评论(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
阅读(67)
评论(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
阅读(105)
评论(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
阅读(67)
评论(0)
推荐(0)
摘要:
``` class Solution { public: vector postorderTraversal(TreeNode* root) { if (!root) return {}; vector res; stack s{{root}}; TreeNode *head = root; while (!s... 阅读全文
posted @ 2019-04-10 10:38
JohnRed
阅读(64)
评论(0)
推荐(0)
摘要:
``` class Solution { public: vector preorderTraversal(TreeNode* root) { if (!root) return {}; vector res; stack s{{root}}; while (!s.empty()) { TreeNode... 阅读全文
posted @ 2019-04-10 10:35
JohnRed
阅读(76)
评论(0)
推荐(0)
摘要:
``` class Solution { public: void reorderList(ListNode *head) { if (!head || !head->next || !head->next->next) return; stack st; ListNode *cur = head; while (cur) {... 阅读全文
posted @ 2019-04-10 10:32
JohnRed
阅读(127)
评论(0)
推荐(0)
摘要:
```
class Solution {
public: ListNode *detectCycle(ListNode *head) { ListNode *slow = head, *fast = head; while (fast && fast->next) { slow = slow->next; fa... 阅读全文
posted @ 2019-04-10 10:29
JohnRed
阅读(57)
评论(0)
推荐(0)
摘要:
```
class Solution {
public: bool hasCycle(ListNode *head) { ListNode *slow = head, *fast = head; while (fast && fast->next) { slow = slow->next; fast = fas... 阅读全文
posted @ 2019-04-10 10:28
JohnRed
阅读(74)
评论(0)
推荐(0)
摘要:
``` class Solution { vector midres; vector res; vector *dp; public: vector wordBreak(string s, unordered_set &dict) { int len = s.length(); dp ... 阅读全文
posted @ 2019-04-10 10:27
JohnRed
阅读(92)
评论(0)
推荐(0)
摘要:
``` class Solution { public: bool wordBreak(string s, vector& wordDict) { unordered_set wordSet(wordDict.begin(), wordDict.end()); vector dp(s.size() 阅读全文
posted @ 2019-04-10 10:23
JohnRed
阅读(120)
评论(0)
推荐(0)
摘要:
``` class Solution { public: RandomListNode *copyRandomList(RandomListNode *head) { if (!head) return NULL; RandomListNode *res = new RandomListNode(head->label); RandomLis... 阅读全文
posted @ 2019-04-10 09:57
JohnRed
阅读(78)
评论(0)
推荐(0)
摘要:
``` class Solution { public: int singleNumber(vector& nums) { int res = 0; for (int i = 0; i i) & 1; } res |= (sum % 3) & nums) { int one = 0, two = 0 阅读全文
posted @ 2019-04-10 09:52
JohnRed
阅读(96)
评论(0)
推荐(0)
摘要:
``` class Solution { public: int singleNumber(int A[], int n) { //异或 int elem = 0; for(int i = 0; i 阅读全文
posted @ 2019-04-10 09:49
JohnRed
阅读(108)
评论(0)
推荐(0)
摘要:
``` class Solution { public: int candy(vector& ratings) { int res = 0, n = ratings.size(); vector nums(n, 1); for (int i = 0; i ratings[i]) nums[i + 1] = nums[i] + 1; ... 阅读全文
posted @ 2019-04-10 09:41
JohnRed
阅读(91)
评论(0)
推荐(0)
摘要:
``` class Solution { public: int canCompleteCircuit(vector& gas, vector& cost) { int total = 0, sum = 0, start = 0; for (int i = 0; i 阅读全文
posted @ 2019-04-10 09:40
JohnRed
阅读(99)
评论(0)
推荐(0)
摘要:
``` class Solution { public: Node* cloneGraph(Node* node) { unordered_map m; return helper(node, m); } Node* helper(Node* node, unordered_map& m) { if (!node) retur... 阅读全文
posted @ 2019-04-10 09:39
JohnRed
阅读(67)
评论(0)
推荐(0)
摘要:
``` class Solution { public: int minCut(string s) { if (s.empty()) return 0; int n = s.size(); vector p(n, vector(n)); vector dp(n); for (int i = 0; i 阅读全文
posted @ 2019-04-10 09:37
JohnRed
阅读(52)
评论(0)
推荐(0)
摘要:
``` class Solution { public: vector partition(string s) { int n = s.size(); vector res; vector out; vector dp(n, vector(n)); for (int i = 0; i & dp, v 阅读全文
posted @ 2019-04-10 09:36
JohnRed
阅读(72)
评论(0)
推荐(0)
摘要:
``` class Solution { public: void solve(vector & board) { if (board.empty() || board[0].empty()) return; int m = board.size(), n = board[0].size(); fo 阅读全文
posted @ 2019-04-10 09:34
JohnRed
阅读(82)
评论(0)
推荐(0)

浙公网安备 33010602011771号