摘要: https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree/ 1 /** 2 * Definition for a binary tree node. 3 * struct TreeNode { 4 * ... 阅读全文
posted @ 2015-07-13 15:58 阿怪123 阅读(129) 评论(0) 推荐(0)
摘要: https://leetcode.com/problems/maximum-subarray/动态规划:用res数组来记录包含了每个点的连续数组的和的最大的情况解的情况,后续的每次计算参考前面的计算结果。 1 class Solution { 2 public: 3 int maxSubAr... 阅读全文
posted @ 2015-07-13 15:37 阿怪123 阅读(135) 评论(0) 推荐(0)
摘要: https://leetcode.com/problems/gray-code/ 1 class Solution { 2 public: 3 vector grayCode(int n) { 4 vector res; 5 if(n==0) 6 ... 阅读全文
posted @ 2015-07-13 15:04 阿怪123 阅读(159) 评论(0) 推荐(0)
摘要: https://leetcode.com/problems/search-a-2d-matrix/ 1 class Solution { 2 public: 3 bool searchMatrix(vector>& matrix, int target) { 4 int m=... 阅读全文
posted @ 2015-07-13 14:15 阿怪123 阅读(126) 评论(0) 推荐(0)
摘要: https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/ 1 class Solution { 2 public: 3 int findMin(vector& nums) { 4 int size=... 阅读全文
posted @ 2015-07-13 11:38 阿怪123 阅读(134) 评论(0) 推荐(0)
摘要: https://leetcode.com/problems/unique-paths/递归问题转换成动态规划问题。每个问题可以分解成p[m][n]=p[m-1][n]+p[m][n-1]动态规划:做一个动态二维数组,用于存放每步的解。最终的循环就是矩阵的所有点遍历一遍。时间复杂度为m*n的矩阵遍历。... 阅读全文
posted @ 2015-07-13 10:48 阿怪123 阅读(128) 评论(0) 推荐(0)
摘要: https://leetcode.com/problems/merge-two-sorted-lists/ 1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ... 阅读全文
posted @ 2015-07-13 10:31 阿怪123 阅读(127) 评论(0) 推荐(0)