• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
ying_vincent
博客园    首页    新随笔    联系   管理    订阅  订阅
2013年3月19日
LeetCode: Count and Say
摘要: 题意理解有误,看了网上答案才弄出来 1 class Solution { 2 public: 3 string countAndSay(int n) { 4 // Start typing your C/C++ solution below 5 // DO N... 阅读全文
posted @ 2013-03-19 19:34 ying_vincent 阅读(159) 评论(0) 推荐(0)
LeetCode: Convert Sorted List to Binary Search Tree
摘要: 第一次想用懒汉方法把list弄成vector再照前一题的方法,结果被判Memory exceed了。。然后只好再写次 1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 *... 阅读全文
posted @ 2013-03-19 16:44 ying_vincent 阅读(153) 评论(0) 推荐(0)
LeetCode: Convert Sorted Array to Binary Search Tree
摘要: 一次过 1 /** 2 * Definition for binary tree 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * TreeNod... 阅读全文
posted @ 2013-03-19 16:05 ying_vincent 阅读(161) 评论(0) 推荐(0)
LeetCode: Container With Most Water
摘要: 第一次用了个O(n^2)的算法large没过,就仔细想了想,少数次过吧 1 class Solution { 2 public: 3 int maxArea(vector &height) { 4 // Start typing your C/C++ solution bel... 阅读全文
posted @ 2013-03-19 15:37 ying_vincent 阅读(146) 评论(0) 推荐(0)
LeetCode: Construct Binary Tree from Preorder and Inorder Traversa
摘要: 跟inorder and postorder基本一样,一次过吧 1 /** 2 * Definition for binary tree 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeN... 阅读全文
posted @ 2013-03-19 15:21 ying_vincent 阅读(173) 评论(0) 推荐(0)
LeetCode: Construct Binary Tree from Inorder and Postorder Traversal
摘要: 第一次只用4个系数写dfs怎么写都不对,后来看了网上的答案发现写右子树的时候开始点不一样的。。。所以要用5个系数 1 /** 2 * Definition for binary tree 3 * struct TreeNode { 4 * int val; 5 * TreeN... 阅读全文
posted @ 2013-03-19 15:02 ying_vincent 阅读(179) 评论(0) 推荐(0)
LeetCode: Combinations
摘要: 初始系数没弄好,改了一次 加一个iterative的方法 C# 1 public class Solution { 2 public List<List<int>> Combine(int n, int k) { 3 List<List<int>> ans = new List<List<int>> 阅读全文
posted @ 2013-03-19 13:50 ying_vincent 阅读(129) 评论(0) 推荐(0)
LeetCode: Combination Sum II
摘要: 改了挺多次,不过最后还是被我搞出来了^^, 用了map的技巧勉强过了large。 1 class Solution { 2 public: 3 void dfs(vector num, int target, int sum, vector &save, map, int> &reti, i... 阅读全文
posted @ 2013-03-19 13:39 ying_vincent 阅读(182) 评论(0) 推荐(0)
LeetCode: Combination Sum
摘要: 第一次没考虑到要加个系数cur, 因为必须从小到大排序,导致答案里有[1, 2]和[2, 1],加入cur后就acm了 1 class Solution { 2 public: 3 void dfs(vector candidates, int target, int sum, vector... 阅读全文
posted @ 2013-03-19 11:56 ying_vincent 阅读(148) 评论(0) 推荐(0)
LeetCode: Climbing Stairs
摘要: 一开始用dfs结果large超时,马上就想到dp了。。哎,下次先得去想dp啊。。 1 class Solution { 2 public: 3 int climbStairs(int n) { 4 // Start typing your C/C++ solution bel... 阅读全文
posted @ 2013-03-19 11:42 ying_vincent 阅读(141) 评论(0) 推荐(0)
LeetCode: Binary Tree Zigzag Level Order Traversal
摘要: 出错了一次,改了一次,小失误没用弄好zigzag的排序。题目还是简单的 1 /** 2 * Definition for binary tree 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * T... 阅读全文
posted @ 2013-03-19 11:34 ying_vincent 阅读(196) 评论(0) 推荐(0)
LeetCode: Binary Tree Maximum Path Sum
摘要: 这题比较难,没理顺关系,做了很多次还只是过了small judge,于是去看网上答案,然后再改了改,关键在于local_max和globe_max,globe_max要随时改得,而maxsum函数只是返回最大路径 1 /** 2 * Definition for binary tree 3 * ... 阅读全文
posted @ 2013-03-19 11:13 ying_vincent 阅读(190) 评论(0) 推荐(0)
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3