• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
ying_vincent
博客园    首页    新随笔    联系   管理    订阅  订阅
上一页 1 ··· 16 17 18 19 20 21 22 23 24 ··· 27 下一页
2013年4月20日
LeetCode: Regular Expression Matching
摘要: 这题改了很多次写了很多种case的代码,虽然通过了,但是感觉自己写得太繁琐了,网上找到一个非常简单的代码。这道题的if语句应该着重在*(p+1),我自己写的着重在*p了,这样就弄得很麻烦,而且最后运行时间也长。 1 class Solution { 2 public: 3 bool isMatch(const char *s, const char *p) { 4 if (*p == '\0') return *s == '\0'; 5 if (*(p+1) != '*') return *s == *p || *p == '.' 阅读全文
posted @ 2013-04-20 04:27 ying_vincent 阅读(459) 评论(0) 推荐(0)
LeetCode: Recover Binary Search Tree
摘要: 这题想了很久,看了网上答案,这段代码精髓在于findpos第一个pos是在他下一个node函数里才被发现的,因为第一个pos->val是变大了,所以p是pre,而第二个pos是在他自己本身的函数里被发现的,因为第二个pos->val是变小了,所以就是root。 1 /** 2 * Definiti... 阅读全文
posted @ 2013-04-20 02:52 ying_vincent 阅读(456) 评论(0) 推荐(0)
2013年4月19日
LeetCode: Pow(x, n)
摘要: 早早投降了,看了这个强大的代码 1 class Solution { 2 public: 3 double pow(double x, int n) { 4 // Start typing your C/C++ solution below 5 // DO N... 阅读全文
posted @ 2013-04-19 15:41 ying_vincent 阅读(174) 评论(0) 推荐(0)
LeetCode: Populating Next Right Pointers in Each Node II
摘要: 这题关键是要记录下一层第一个节点 1 /** 2 * Definition for binary tree with next pointer. 3 * struct TreeLinkNode { 4 * int val; 5 * TreeLinkNode *left, *right, ... 阅读全文
posted @ 2013-04-19 14:48 ying_vincent 阅读(176) 评论(2) 推荐(0)
LeetCode: Populating Next Right Pointers in Each Node
摘要: 思路对的,少数次过,基本一次过吧 1 /** 2 * Definition for binary tree with next pointer. 3 * struct TreeLinkNode { 4 * int val; 5 * TreeLinkNode *left, *right, *next; 6 * TreeLinkNode(int x) : val(x), left(NULL), right(NULL), next(NULL) {} 7 * }; 8 */ 9 class Solution {10 public:11 void connect(TreeLi... 阅读全文
posted @ 2013-04-19 14:42 ying_vincent 阅读(132) 评论(0) 推荐(0)
LeetCode: Plus One
摘要: 考vector的insert操作,一次过 1 class Solution { 2 public: 3 vector plusOne(vector &digits) { 4 // Start typing your C/C++ solution below 5 ... 阅读全文
posted @ 2013-04-19 13:14 ying_vincent 阅读(142) 评论(0) 推荐(0)
LeetCode: Permutations II
摘要: 一些小失误,基本一次过,这题可以明显看到自己的进步,map用得比较成熟了 1 class Solution { 2 public: 3 void dfs(int dep, int maxdep, map &s, vector> &ret, vector &tmp) { 4 i... 阅读全文
posted @ 2013-04-19 13:07 ying_vincent 阅读(250) 评论(0) 推荐(0)
LeetCode: Permutations
摘要: 一次过 1 class Solution { 2 public: 3 void dfs(int dep, int maxdep, vector &tmp, vector> &ret, vector num, vector &visit) { 4 if (dep == maxd... 阅读全文
posted @ 2013-04-19 12:07 ying_vincent 阅读(186) 评论(0) 推荐(0)
LeetCode: Permutation Sequence
摘要: 这题的难度在编程,一开始想到的dfs过不了large,第二次想到网上的正确答案的思路,不过没有编出来,然后只好找答案了 1 class Solution { 2 public: 3 string getPermutation(int n, int k) { 4 // Start typing your C/C++ solution below 5 // DO NOT write int main() function 6 string ret = ""; 7 int time = 1; 8 for (int... 阅读全文
posted @ 2013-04-19 11:37 ying_vincent 阅读(403) 评论(1) 推荐(0)
LeetCode: Path Sum II
摘要: 多数次过 1 /** 2 * Definition for binary tree 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * TreeNo... 阅读全文
posted @ 2013-04-19 07:46 ying_vincent 阅读(123) 评论(0) 推荐(0)
上一页 1 ··· 16 17 18 19 20 21 22 23 24 ··· 27 下一页
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3