• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
 






canexjtuzju

记录
 
 

Powered by 博客园
博客园 | 首页 | 新随笔 | 联系 | 订阅 订阅 | 管理

随笔分类 -  LeetCode

1 2 3 下一页

 
LeetCode-- Unique Binary Search Trees II
摘要:递归 1 /** 2 * Definition for binary tree 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * TreeNode... 阅读全文
posted @ 2014-09-12 10:03 canexjtuzju 阅读(133) 评论(0) 推荐(0)
LeetCode--Next Permutation
摘要:(1)从后往前,找到a[i] &num) { 4 int end = num.size() - 1; 5 int povit = end; 6 while(povit > 0){ 7 if(num[povit] > num[po... 阅读全文
posted @ 2014-09-10 21:01 canexjtuzju 阅读(208) 评论(0) 推荐(0)
LeetCode--Wrod Break
摘要:---恢复内容开始--- 1 class Solution { 2 public: 3 bool wordBreak(string s, unordered_set &dict) { 4 int nsize=s.size(); 5 int i=0,j=0; 6... 阅读全文
posted @ 2014-09-08 21:14 canexjtuzju 阅读(131) 评论(0) 推荐(0)
LeetCode--Largest Rectangle in Histogram
摘要:---恢复内容开始--- 1 class Solution { 2 public: 3 int largestRectangleArea(vector &height) { 4 int n = height.size(); 5 if(n == 0) 6 ... 阅读全文
posted @ 2014-09-08 20:56 canexjtuzju 阅读(129) 评论(0) 推荐(0)
LeetCode--Binary Tree Maximum Path Sum
摘要:递归,dfs这里返回值是一个pair,first表示两个子树的不经过当前root的最大pathsum;second表示两个子树的,以root->left和root->right为路径起始节点的路径的最大值 1 /** 2 * Definition for binary tree 3 * stru... 阅读全文
posted @ 2014-09-07 18:55 canexjtuzju 阅读(144) 评论(0) 推荐(0)
LeetCode--Reorder List
摘要:(1)双指针(快慢):找到中节点(2)反转第一或者第二个链表(反转第一个后面合并完了还得再反转),所以建议反转第二个链表代码:暂时不贴了https://oj.leetcode.com/problems/reorder-list/ 阅读全文
posted @ 2014-09-07 15:34 canexjtuzju 阅读(127) 评论(0) 推荐(0)
LeetCode--Combination Sum
摘要:由于需要就地保存清零信息,所以把信息保存在第一行和第一列 1 class Solution { 2 public: 3 void setZeroes(vector > &matrix) { 4 const int ROW = matrix.size(); 5 ... 阅读全文
posted @ 2014-09-06 23:31 canexjtuzju 阅读(148) 评论(0) 推荐(0)
LeetCode--Binary Tree Level Order Traversal
摘要:用两个队列实现,交叉使用,达到判断层的目的 1 /** 2 * Definition for binary tree 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right... 阅读全文
posted @ 2014-09-06 23:17 canexjtuzju 阅读(151) 评论(0) 推荐(0)
LeetCode--Plus One
摘要:考查,最高位有进位 1 class Solution { 2 public: 3 vector plusOne(vector &digits) { 4 // IMPORTANT: Please reset any member data you declared, as 5 ... 阅读全文
posted @ 2014-09-04 22:33 canexjtuzju 阅读(131) 评论(0) 推荐(0)
LeetCode--Combination Sum
摘要:一开始的思路是:中序遍历+判断遍历后的数组,时间空间都不是最优果然超时了 1 /** 2 * Definition for binary tree 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * ... 阅读全文
posted @ 2014-09-04 22:10 canexjtuzju 阅读(171) 评论(0) 推荐(0)
LeetCode--Balanced Binary Tree
摘要:递归 1 /** 2 * Definition for binary tree 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * TreeNode... 阅读全文
posted @ 2014-09-04 21:16 canexjtuzju 阅读(143) 评论(0) 推荐(0)
LeetCode--N-Queens II
摘要:dfs 1 class Solution { 2 public: 3 int res; 4 int totalNQueens(int n) { 5 res = 0; 6 vector arr(n); 7 dfs(arr,0,n); 8 ... 阅读全文
posted @ 2014-09-04 21:07 canexjtuzju 阅读(131) 评论(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... 阅读全文
posted @ 2014-09-04 20:20 canexjtuzju 阅读(155) 评论(0) 推荐(0)
LeetCode--Restore IP Addresses
摘要:dfs即可注意边界情况:(1)s长度不在4 和 12之间(2)"010"这种形式是错误的 1 class Solution { 2 public: 3 vector restoreIpAddresses(string s) { 4 vector res; 5 ... 阅读全文
posted @ 2014-09-04 10:13 canexjtuzju 阅读(148) 评论(0) 推荐(0)
LeetCode--3Sum
摘要:类似于2sum,先排序,然后从左开始遍历,计算a[i]后面的等于-a[i]的两个元素,注意去除重复元素 1 class Solution { 2 public: 3 vector > threeSum(vector &num) { 4 vector > res; 5 ... 阅读全文
posted @ 2014-08-30 22:39 canexjtuzju 阅读(147) 评论(0) 推荐(0)
LeetCode--Insert Interval
摘要:其实可以O(n)的思路,如下 1 class Solution { 2 public: 3 vector insert(vector &intervals, Interval newInterval) { 4 // Start typing your C/C++ soluti... 阅读全文
posted @ 2014-08-27 21:41 canexjtuzju 阅读(228) 评论(0) 推荐(0)
LeetCode--Surrounded Regions
摘要:1 class Solution { 2 public: 3 void solve(vector> &board) { 4 int m = board.size(); 5 if(m == 0) 6 return; 7 ... 阅读全文
posted @ 2014-08-27 21:06 canexjtuzju 阅读(166) 评论(0) 推荐(0)
LeetCode--Container With Most Water
摘要:双指针 1 class Solution { 2 public: 3 int maxArea(vector &height) { 4 if(height.size() == 0 || height.size() == 1) 5 return 0; 6 ... 阅读全文
posted @ 2014-08-27 09:51 canexjtuzju 阅读(140) 评论(0) 推荐(0)
LeetCode--Permutation Sequence
摘要:1 class Solution { 2 public: 3 string getPermutation(int n, int k) { 4 int fac[10]; 5 bool vis[10]; 6 memset(vis, 0, size... 阅读全文
posted @ 2014-08-25 14:06 canexjtuzju 阅读(128) 评论(0) 推荐(0)
LeetCode--Regular Expression Matching
摘要:1 class Solution { 2 public: 3 bool isMatch(const char *s, const char *p) { 4 // Start typing your C/C++ solution below 5 // DO N... 阅读全文
posted @ 2014-08-25 12:46 canexjtuzju 阅读(162) 评论(0) 推荐(0)
 

1 2 3 下一页