leetcode
john_and_betty
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
Set Matrix Zeroes
class Solution { public: void setZeroes(vector > &matrix) { int m=matrix.size(); int n=matrix[0].size(); vectorrow; vectorcol; row.assign(m,0); col.原创 2014-03-11 18:48:20 · 394 阅读 · 0 评论 -
Combination Sum
class Solution { public: vector>res; vector > combinationSum(vector &candidates, int target) { vectorpath; combination(candidates,target,path,0); return res; }原创 2014-03-25 19:25:44 · 357 阅读 · 0 评论 -
Unique PatUnique Paths II
class Solution { public: int uniquePathsWithObstacles(vector > &obstacleGrid) { if(obstacleGrid.size()==0) return 0; int wide=obstacleGrid.size(); int len=obstacleGr原创 2014-03-22 21:19:41 · 365 阅读 · 0 评论 -
binary tree zigzag Level Order Traversal
class Solution { public: vector > zigzagLevelOrder(TreeNode *root){ vector>res; if(root==NULL) return res; vectorpath; vectorpath_val; path_val.原创 2014-03-20 19:21:10 · 383 阅读 · 0 评论 -
Binary Tree Level Order Traversal
class Solution { public: vector > levelOrder(TreeNode *root) { vector path; vectorpath_val; vector> res; if(root==NULL) return res; path.push_ba原创 2014-03-16 13:37:35 · 353 阅读 · 0 评论 -
Construct Binary Tree from Preorder and Inorder Traversal
class Solution { public: TreeNode *buildTree(vector &preorder, vector &inorder) { if(inorder.size()==0) return NULL; return traverse(preorder,0,preorder.size()-1,inorde原创 2014-03-15 13:47:42 · 473 阅读 · 0 评论 -
Merge Two Sorted Lists
一直不理解ListNode dimmy(-1)是什么意思,只会依样画葫芦,这题难度很一般 class Solution { public: ListNode *mergeTwoLists(ListNode *l1, ListNode *l2) { ListNode dummy(-1); ListNode *pre=&dummy; while原创 2014-03-10 13:19:38 · 417 阅读 · 0 评论 -
Maximum Subarray
昨天刚看的扫描算法,现在都可以背下来了 class Solution { public: int maxSubArray(int A[], int n) { int maxh=INT_MIN,maxs=INT_MIN; for(int i=0;i<n;i++) { if(maxh>0)原创 2014-03-10 13:02:59 · 390 阅读 · 0 评论 -
Reverse words in a String leetcode
class Solution { public: void reverseWords(string &s) { vector temp; string str; for(int i=0;i<s.length();i++) { if(s[i]!=' ') {原创 2014-03-07 11:23:55 · 559 阅读 · 0 评论 -
Search in Rotated Sorted Array II
class Solution { public: bool search(int A[], int n, int target) { for(int i=0;i<n;i++) { if(A[i]==target) return true; } return false原创 2014-03-13 19:56:32 · 372 阅读 · 0 评论 -
Combinations
鼓掌鼓掌,刷题以来,第一道一次accept的题目,也难怪通过率这么高 class Solution { public: vector> res; vector > combine(int n, int k) { vectorpath; process(n,1,k,path); return res; }原创 2014-03-13 19:21:43 · 296 阅读 · 0 评论 -
Triangle
class Solution { public: int minimumTotal(vector > &triangle) { vector res2; res2.resize(triangle.size()); res2[0]=triangle[0][0]; for(int i=1;i<triangle.size();i++原创 2014-03-08 13:37:14 · 459 阅读 · 0 评论 -
Valid Sudoku
class Solution { public: bool isValidSudoku(vector > &board) { for(int i=0;i<9;i++) for(int j=0;j<9;j++) { if(board[i][j]!='.') if(!i原创 2014-03-26 19:58:26 · 392 阅读 · 0 评论
分享