leetcode
freshXD
爱是势均力敌
展开
-
leetcode jumpgame 2
class Solution{ public: int jump(int A[], int n){ if(n < 2){ //when less than two elements, no need to jump return 0; } int ll = 0, rr = 0, step = 0, lastrr = 0; while(true){ i原创 2015-02-23 21:17:04 · 410 阅读 · 0 评论 -
leetcode merge interval
/** * Definition for an interval. * struct Interval { * int start; * int end; * Interval() : start(0), end(0) {} * Interval(int s, int e) : start(s), end(e) {} * }; */ class Sol原创 2015-04-08 18:12:07 · 415 阅读 · 0 评论 -
leetcode unique paths ii
class Solution { public: int uniquePathsWithObstacles(vector<vector<int> > &obstacleGrid) { int h = obstacleGrid.size(); if(h == 0){ return 0; } int w =原创 2015-04-08 16:38:08 · 314 阅读 · 0 评论 -
leetcode Rotate List
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode *rot原创 2015-04-08 21:48:16 · 339 阅读 · 0 评论 -
leetcode Insert Interval
/** * Definition for an interval. * struct Interval { * int start; * int end; * Interval() : start(0), end(0) {} * Interval(int s, int e) : start(s), end(e) {} * }; */ class Sol原创 2015-04-08 21:00:48 · 332 阅读 · 0 评论 -
leetcode rotate image
class Solution { public: void rotate(vector<vector<int> > &matrix) { int n = matrix.size(); if(n < 2){ return; } int hl = 0, hr = n - 1, vu = 0, vd = n -原创 2015-04-08 19:52:45 · 325 阅读 · 0 评论 -
leetcode Number of Islands
class Solution { public: const int dir[4][2] = {{-1,0},{1,0},{0,-1},{0,1}}; bool valid(int x, int y, int h, int w, vector<vector<char> >&grid){ return x >= 0 && x < h && y >= 0 && y < w原创 2015-04-16 11:26:51 · 354 阅读 · 0 评论 -
leetcode Reverse Linked List
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode *rev原创 2015-04-15 23:17:07 · 368 阅读 · 0 评论 -
leetcode Restore IP Address
class Solution { public: inline int getlen(int digit){ return digit == 0 ? 1 : (((int)log10(digit)) + 1); } void dfs(const string& s, const int totlen, int index, int cur, int partn原创 2015-04-16 00:37:37 · 394 阅读 · 0 评论 -
leetcode Sudoku Solver
class Solution { public: int flip(int i){ int ret = 1 << i; ret = ~ret; return ret; } bool valid(int v, int x, int y, vector<int>&row, vector<int>&column, vector<int原创 2015-04-16 13:03:01 · 334 阅读 · 0 评论 -
leetcode Sort Colors
class Solution { public: void sortColors(int A[], int n) { int cntZero = 0, cntTwo = 0; for(int i = 0; i < n; ++i){ cntZero += A[i] == 0 ? 1 : 0; cntTwo += A原创 2015-04-08 21:37:59 · 357 阅读 · 0 评论 -
leetcode word ladder bfs
先贴代码:class Solution { public: //void expand(queue<string>&sq, ) int ladderLength(string start, string end, unordered_set<string> &dict) { int slen = start.length(); int rlen = 0原创 2015-04-08 13:36:51 · 352 阅读 · 0 评论 -
leetcode partition list
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode *par原创 2015-04-08 23:51:10 · 378 阅读 · 0 评论 -
leetcode maximum gap
先贴代码: class Solution{ public: /*by default, numbers in num vector is non-negative integers within 32 signed bits*/ int maximumGap(vector &num){ int size = num.size(); if(size < 2){ //if len原创 2015-02-23 22:13:36 · 396 阅读 · 0 评论 -
leetcode Find Minimum in Rotated Array
class Solution { public: int findMin(vector<int> &num) { int size = num.size(); if(size == 0){ return 0; } if(size == 1){ return num[0];原创 2015-03-19 18:34:59 · 341 阅读 · 0 评论 -
leetcode 想不出算法的题
Best time to buy and sell stock 2原创 2015-03-26 01:28:09 · 426 阅读 · 0 评论 -
leetcode Sort List
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode *sor原创 2015-03-17 01:08:07 · 382 阅读 · 0 评论 -
leetcode Plus One
class Solution { public: vector<int> plusOne(vector<int> &digits) { int size = digits.size(); if(size == 0){ digits.push_back(1); return digits; }原创 2015-03-17 01:20:25 · 313 阅读 · 0 评论 -
leetcode Remove Nth Node from Linked List
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode *rem原创 2015-03-21 01:30:43 · 394 阅读 · 0 评论 -
leetcode Excel Sheet Column Number
class Solution { public: int titleToNumber(string s) { long long ret = 0; int len = s.length(); if(len == 0){ return ret; } long long base = 1;原创 2015-03-21 09:29:06 · 305 阅读 · 0 评论 -
leetcode Set Matrix Zero
class Solution { public: void setZeroes(vector<vector<int> > &matrix) { int h = matrix.size(); if(h == 0){ return; } int w = matrix[0].size(); if原创 2015-04-08 23:35:14 · 413 阅读 · 0 评论 -
leetcode Remove Duplicates From Sorted List
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode *del原创 2015-04-08 21:20:16 · 340 阅读 · 0 评论 -
db碎碎念
db中一个table的foreign key必须是另一个table的primary key么? 如何使得两个table中主码互为对方的外码 参考了https://social.msdn.microsoft.com/Forums/sqlserver/en-US/431c8ca9-5c4e-402b-8af0-cd58b71c2429/2-tables-referencing-each-other-u原创 2015-04-15 23:16:38 · 401 阅读 · 0 评论