• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
ying_vincent
博客园    首页    新随笔    联系   管理    订阅  订阅
2013年4月9日
LeetCode: Minimum Path Sum
摘要: dp题,基本一次过 1 class Solution { 2 public: 3 int minPathSum(vector > &grid) { 4 // Start typing your C/C++ solution below 5 // DO NOT ... 阅读全文
posted @ 2013-04-09 18:11 ying_vincent 阅读(159) 评论(0) 推荐(0)
LeetCode: Minimum Depth of Binary Tree
摘要: 简单题,少数次过 1 /** 2 * Definition for binary tree 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * Tr... 阅读全文
posted @ 2013-04-09 17:59 ying_vincent 阅读(144) 评论(0) 推荐(0)
LeetCode: Merge Two Sorted Lists
摘要: 一点小失误,两次过 1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ListNode *next; 6 * ListNode(int x) : v... 阅读全文
posted @ 2013-04-09 17:42 ying_vincent 阅读(138) 评论(0) 推荐(0)
LeetCode: Merge Sorted Array
摘要: 一点小失误,基本一次过吧,这段程序不好,参考C# 1 class Solution { 2 public: 3 void merge(int A[], int m, int B[], int n) { 4 // Start typing your C/C++ solution... 阅读全文
posted @ 2013-04-09 17:35 ying_vincent 阅读(124) 评论(0) 推荐(0)
LeetCode: Merge k Sorted Lists
摘要: 自己写的太复杂了,一开始想的是给开始的lists头们排序,然后从这个序列的第一个抽出来,然后再重新用二分法进行排序,不过这个方法large超时了,看了网上的发现还是用很土地方法用一个for循环从前两个开始merge到最后,不知道为什么自己把这个想这么复杂。 1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ListNode *next; 6 * ListNode(int x) : val(x), next(NULL) {} 7 * }; 8 ... 阅读全文
posted @ 2013-04-09 17:22 ying_vincent 阅读(188) 评论(0) 推荐(0)
LeetCode: Merge Intervals
摘要: 出了个小问题,但是这问题又那么蛋疼。。bool cmp这函数不能放在solution里,我也不知道为什么,放外面就能过 1 /** 2 * Definition for an interval. 3 * struct Interval { 4 * int start; 5 * ... 阅读全文
posted @ 2013-04-09 15:22 ying_vincent 阅读(196) 评论(0) 推荐(0)
LeetCode: Median of Two Sorted Arrays
摘要: 这题难度在编程,看了网上答案 1 class Solution { 2 public: 3 int dfs(int A[], int m, int B[], int n, int k) 4 { 5 if (m <= 0) return B[k-1]; 6 if (n <= 0) return A[k-1]; 7 if (k <= 1) return min(A[0], B[0]); 8 if (B[n/2] >= A[m/2] && (m/2+n/2+1 >= k)) return dfs(A... 阅读全文
posted @ 2013-04-09 14:49 ying_vincent 阅读(271) 评论(0) 推荐(0)
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3