• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
ying_vincent
博客园    首页    新随笔    联系   管理    订阅  订阅
2013年4月20日
LeetCode: Search for a Range
摘要: 一次过 1 class Solution { 2 public: 3 vector searchRange(int A[], int n, int target) { 4 // Start typing your C/C++ solution below 5 ... 阅读全文
posted @ 2013-04-20 16:41 ying_vincent 阅读(155) 评论(0) 推荐(0)
LeetCode: Search a 2D Matrix
摘要: 少数次过 1 class Solution { 2 public: 3 bool searchMatrix(vector > &matrix, int target) { 4 // Start typing your C/C++ solution below 5 ... 阅读全文
posted @ 2013-04-20 16:33 ying_vincent 阅读(140) 评论(0) 推荐(0)
LeetCode: Same Tree
摘要: 一次过 1 /** 2 * Definition for binary tree 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * TreeNod... 阅读全文
posted @ 2013-04-20 15:19 ying_vincent 阅读(130) 评论(0) 推荐(0)
LeetCode: Rotate List
摘要: 两个边界条件没考虑到,少数次过 1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ListNode *next; 6 * ListNode(int ... 阅读全文
posted @ 2013-04-20 15:16 ying_vincent 阅读(146) 评论(0) 推荐(0)
LeetCode: Rotate Image
摘要: 好麻烦的一道题,完全是算术。。少数次过 1 class Solution { 2 public: 3 void rotate(vector > &matrix) { 4 // Start typing your C/C++ solution below 5 /... 阅读全文
posted @ 2013-04-20 15:00 ying_vincent 阅读(217) 评论(0) 推荐(0)
LeetCode: Reverse Nodes in k-Group
摘要: 从这题和上一题可以总结出反转链表的经验,需要有5个指针:end, q, p, pPre, pNext. p和pPre进行方向转置后p和pPre向后移,pNext用来记录转置前p的后一个,q用来记录转置串之前的node,end记录转置串最开始的node。 1 /** 2 * Definition f... 阅读全文
posted @ 2013-04-20 13:06 ying_vincent 阅读(158) 评论(0) 推荐(0)
LeetCode: Reverse Linked List II
摘要: 没做出来,看网上答案,这题难度在于编程 1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ListNode *next; 6 * ListNode(... 阅读全文
posted @ 2013-04-20 08:45 ying_vincent 阅读(138) 评论(0) 推荐(0)
LeetCode: Reverse Integer
摘要: 一次过 1 class Solution { 2 public: 3 int reverse(int x) { 4 // Start typing your C/C++ solution below 5 // DO NOT write int main() f... 阅读全文
posted @ 2013-04-20 07:13 ying_vincent 阅读(133) 评论(0) 推荐(0)
LeetCode: Restore IP Addresses
摘要: erase的时候没考虑到.加上去之后删除位置的变化,基本一次过,少数次过 1 class Solution { 2 public: 3 void dfs(vector &ret, string tmp, string s, int dep, int maxsize, int beg) { 4... 阅读全文
posted @ 2013-04-20 07:08 ying_vincent 阅读(234) 评论(0) 推荐(0)
LeetCode: Remove Nth Node From End of List
摘要: 一次过 1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ListNode *next; 6 * ListNode(int x) : val(x),... 阅读全文
posted @ 2013-04-20 06:33 ying_vincent 阅读(132) 评论(0) 推荐(0)
LeetCode: Remove Element
摘要: 简单题, 一次过 1 class Solution { 2 public: 3 int removeElement(int A[], int n, int elem) { 4 // Start typing your C/C++ solution below 5 ... 阅读全文
posted @ 2013-04-20 06:16 ying_vincent 阅读(155) 评论(0) 推荐(0)
LeetCode: Remove Duplicates from Sorted List II
摘要: 忘了边界条件,少数次过 1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ListNode *next; 6 * ListNode(int x) :... 阅读全文
posted @ 2013-04-20 06:11 ying_vincent 阅读(181) 评论(0) 推荐(0)
LeetCode: Remove Duplicates from Sorted List
摘要: list比array更简单, 一次过 1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ListNode *next; 6 * ListNode(i... 阅读全文
posted @ 2013-04-20 05:08 ying_vincent 阅读(134) 评论(0) 推荐(0)
LeetCode: Remove Duplicates from Sorted Array II
摘要: 在上一题的基础上加了个bool twice,一次过 1 class Solution { 2 public: 3 int removeDuplicates(int A[], int n) { 4 // Start typing your C/C++ solution belo... 阅读全文
posted @ 2013-04-20 05:04 ying_vincent 阅读(123) 评论(0) 推荐(0)
LeetCode: Remove Duplicates from Sorted Array
摘要: 很奇怪这种小问题会多数次过。。太小看他了 1 class Solution { 2 public: 3 int removeDuplicates(int A[], int n) { 4 // Start typing your C/C++ solution below 5 ... 阅读全文
posted @ 2013-04-20 04:56 ying_vincent 阅读(151) 评论(0) 推荐(0)
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 阅读(461) 评论(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 阅读(462) 评论(0) 推荐(0)
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3