红桃J

用心写好每行完美的代码,远比写一堆更有价值

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 :: 管理 ::

随笔分类 -  算法

1 2 3 下一页

摘要:树结构无论是组织数据,还是行使特定功能都是一种强大的武器,今天我们来详细解读一下字典树。字典树:字典树是一种特殊的搜索树,可以用来统计字符串数量,统计前缀词频。字典树有以下基本性质:1.有一个根节点,但根节点无数据。2.每个节点有N个出度(N为组成字符串的字符的类型数目),即字典树是个N叉树3.节点... 阅读全文
posted @ 2015-09-20 11:16 红桃J 阅读(1977) 评论(0) 推荐(1)

该文被密码保护。
posted @ 2015-09-18 18:13 红桃J 阅读(5) 评论(0) 推荐(0)

摘要:代码: 1 #include 2 #include 3 #include 4 5 using namespace std; 6 7 struct Interval { 8 int start; 9 int end;10 Interval() : start(0), end... 阅读全文
posted @ 2015-07-14 21:32 红桃J 阅读(178) 评论(0) 推荐(0)

摘要:第一个的代码: 1 #include 2 #include 3 4 using namespace std; 5 6 bool isLegal(int i, int j, vector &current) 7 { 8 int size = current.size(); 9 in... 阅读全文
posted @ 2015-07-01 20:01 红桃J 阅读(191) 评论(0) 推荐(0)

摘要:代码: 1 #include 2 #include 3 4 using namespace std; 5 6 vector spiralOrder(vector>& matrix) 7 { 8 if (matrix.size() == 0) 9 return vector... 阅读全文
posted @ 2015-07-01 16:46 红桃J 阅读(196) 评论(0) 推荐(0)

摘要:代码: 1 #include 2 #include 3 4 using namespace std; 5 6 struct ListNode { 7 int val; 8 ListNode *next; 9 ListNode(int x) : val(x), ne... 阅读全文
posted @ 2015-07-01 16:21 红桃J 阅读(201) 评论(0) 推荐(0)

摘要:就是转圈圈!代码:#include#includeusing namespace std;void rotate(vector>& matrix) { int L = matrix.size(); int i = 0; while (i > matrix = { ... 阅读全文
posted @ 2015-06-25 21:51 红桃J 阅读(153) 评论(0) 推荐(0)

摘要:代码: 1 #include 2 #include 3 4 using namespace std; 5 6 void getResult(vector> &result, vector element, vector nums) 7 { 8 if (element.size() == ... 阅读全文
posted @ 2015-06-15 18:46 红桃J 阅读(192) 评论(0) 推荐(0)

摘要:代码: 1 #include 2 #include 3 #include 4 5 using namespace std; 6 7 void swap(char &a, char &b) 8 { 9 char c = a;10 a = b;11 b = c;12 }13 ... 阅读全文
posted @ 2015-06-11 23:42 红桃J 阅读(155) 评论(0) 推荐(0)

摘要:无脑写代码代码(TLE): 1 #include 2 #include 3 4 using namespace std; 5 6 int findLeft(int i, vector height) 7 { 8 int t = i-1; 9 while ((t+1= 0)10 ... 阅读全文
posted @ 2015-05-16 16:41 红桃J 阅读(210) 评论(0) 推荐(0)

摘要:代码: 1 #include 2 #include 3 4 using namespace std; 5 6 void swap(int &a, int &b) 7 { 8 int c = a; 9 a = b;10 b = c;11 }12 13 int firstMi... 阅读全文
posted @ 2015-05-16 16:17 红桃J 阅读(174) 评论(0) 推荐(0)

摘要:这个题目其实和之前的没有什么区别,只是添加了21到29这一段更新i的代码。这个题目是说在之前题目的基础上允许candidates集合有相同的元素,那么该剔除相同元素的关键在于发现是什么产生了相同的元素。在回溯时如果我们加入了数字a,最后在退出a的时候,如果下一个数字还是a,那么我把它加进去显然这个子... 阅读全文
posted @ 2015-05-15 10:53 红桃J 阅读(156) 评论(0) 推荐(0)

摘要:终于搞定了这个DFS,最近这个DFS写的很不顺手,我一直以为递归这种东西只是在解重构时比较麻烦,现在看来,连最简单的返回true和false的逻辑关系都不能说one hundred present 搞定。人品啊TLE: 1 class Solution { 2 public: 3 bool lega... 阅读全文
posted @ 2015-05-14 19:38 红桃J 阅读(194) 评论(0) 推荐(0)

摘要:代码:个人浅薄的认为DFS就是回溯法中的一种,一般想到用DFS我们脑中一般都有一颗解法树,然后去按照深度优先搜索去寻找解。而分支界限法则不算是回溯,无论其是采用队列形式的还是优先队列形式的分支界限法。下面这个函数就是我的DFS的函数,先介绍一下参数的含义,index表示当前要判断是否合适的candi... 阅读全文
posted @ 2015-05-13 15:42 红桃J 阅读(534) 评论(0) 推荐(0)

摘要:代码: 1 #include 2 #include 3 #include 4 5 using namespace std; 6 7 8 string countAndSay(int n) 9 {10 string s = "1";11 int i = 0; 12 wh... 阅读全文
posted @ 2015-05-13 15:30 红桃J 阅读(137) 评论(0) 推荐(0)

摘要:下面是这两个题的解法:参考博客:http://blog.csdn.net/loverooney/article/details/38455475自己写的第一题(TLE): 1 #include 2 #include 3 4 using namespace std; 5 6 bool canJum... 阅读全文
posted @ 2015-05-12 19:53 红桃J 阅读(246) 评论(0) 推荐(0)

摘要:代码:/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : va... 阅读全文
posted @ 2015-05-11 22:36 红桃J 阅读(104) 评论(0) 推荐(0)

摘要:异或运算的使用代码: 1 int singleNumber(int* nums, int numsSize) { 2 int i, result = nums[0]; 3 if(numsSize<=0) 4 return 0; 5 f... 阅读全文
posted @ 2015-05-11 22:24 红桃J 阅读(147) 评论(0) 推荐(0)

摘要:代码: 1 #include 2 #include 3 4 using namespace std; 5 6 int search(vector& nums, int target) 7 { 8 int L = nums.size(); 9 int k = 0;10 i... 阅读全文
posted @ 2015-05-11 19:07 红桃J 阅读(161) 评论(0) 推荐(0)

摘要:错误代码: 1 #include 2 3 using namespace std; 4 5 int longestValidParentheses(string s) 6 { 7 int i = 0; 8 int L = s.length(); 9 int j;10 ... 阅读全文
posted @ 2015-05-11 11:32 红桃J 阅读(144) 评论(0) 推荐(0)

1 2 3 下一页