02 2015 档案

摘要:本文翻译自How to Write Doc Comments for the Javadoc Tool,但是精简了一些私以为不重要的东西本文不讨论如何使用javadoc工具自动生成文档的方法,而是主要探讨应该如何去写文档注释业余时间整理,难免有遗漏或错误,如有发现欢迎指正转载请注明文档注释概览“文档... 阅读全文
posted @ 2015-02-05 15:45 李舜阳 阅读(57012) 评论(2) 推荐(11)
摘要:原题地址罗马数字的问题可以参考这篇博文,讲的很清楚代码: 1 int transfer(char c) { 2 switch (c) { 3 case 'I': return 1; 4 case 'V': return 5; 5 case 'X': return 10; 6 ca... 阅读全文
posted @ 2015-02-02 19:52 李舜阳 阅读(400) 评论(0) 推荐(0)
摘要:原题地址辅助栈代码: 1 bool isValid(string s) { 2 stack st; 3 4 for (auto c : s) { 5 if (st.empty()) 6 st.p... 阅读全文
posted @ 2015-02-02 19:21 李舜阳 阅读(156) 评论(0) 推荐(0)
摘要:原题地址如果不使用额外的空间,可以先将A数组整体向后挪n个单位,然后开始常规的merge操作代码: 1 void merge(int A[], int m, int B[], int n) { 2 int i = m - 1; 3 int j = 0; 4 ... 阅读全文
posted @ 2015-02-02 19:05 李舜阳 阅读(127) 评论(0) 推荐(0)
摘要:原题地址注意从1开始索引,所以记得+1代码: 1 int titleToNumber(string s) { 2 int res = 0; 3 4 for (int i = 0; i < s.length(); i++) { 5 ... 阅读全文
posted @ 2015-02-02 18:53 李舜阳 阅读(156) 评论(0) 推荐(0)
摘要:原题地址26进制数注意,编号是从1开始的,所以取模取商之前要-1代码: 1 string convertToTitle(int n) { 2 string res; 3 4 while (n) { 5 res = (char)... 阅读全文
posted @ 2015-02-02 18:46 李舜阳 阅读(119) 评论(0) 推荐(0)
摘要:原题地址先将A链末尾和B链头部接起来然后判断是否有环,如果无环,说明肯定不想交,如果有环,那么相交的位置就是环开始的位置第一遍做的时候没遇到什么问题,第二遍做的时候各种出错,后来发现原来在用快慢指针法的时候快慢指针要从起点开始,否则计算出来的第一个相交位置不是环开始的位置。。代码: 1 ListNo... 阅读全文
posted @ 2015-02-02 18:22 李舜阳 阅读(168) 评论(0) 推荐(0)
摘要:原题地址找规律题代码: 1 string convert(string s, int nRows) { 2 string res; 3 4 if (nRows <= 1) 5 return s; 6 7 ... 阅读全文
posted @ 2015-02-02 16:57 李舜阳 阅读(145) 评论(0) 推荐(0)
摘要:原题地址非常恶心的一道题,又是处理溢出问题根据经验,处理溢出问题应该:优先在还没溢出的时候检测运算后的结果是否会溢出,而不是等到溢出以后再去判断结果是否溢出比如,为了判断F(x)是否会溢出,应该推算出x的合法范围,当x不在合法范围内时,判定溢出。而不是计算出F(x)的值之后再判断是否会溢出。有时候计... 阅读全文
posted @ 2015-02-02 16:26 李舜阳 阅读(206) 评论(0) 推荐(0)
摘要:原题地址注意溢出问题代码: 1 int reverse(int x) { 2 int newx = 0; 3 4 while (x) { 5 if ((newx * 10 / 10) != newx) 6 ... 阅读全文
posted @ 2015-02-02 15:56 李舜阳 阅读(125) 评论(0) 推荐(0)
摘要:原题地址方法I:传统的判断回文的方法,左右指针,不断收缩判断方法II:将数字翻转,判断翻转后的数字是否相等,溢出也没关系因为溢出以后更加不可能相等了代码(方法II): 1 bool isPalindrome(int x) { 2 int oldx = x; 3 int... 阅读全文
posted @ 2015-02-02 15:38 李舜阳 阅读(133) 评论(0) 推荐(0)
摘要:原题地址isalnum:判断是否是字符或数字toupper:将字符转换成大写,非字符不变代码: 1 bool isPalindrome(string s) { 2 string news; 3 for (auto c : s) 4 if (is... 阅读全文
posted @ 2015-02-02 15:28 李舜阳 阅读(123) 评论(0) 推荐(0)
摘要:原题地址从编号为0开始,不断递推到第k个如果用p[i][j]表示第i层,第j个数字,则有递推公式:p[i][j] = p[i-1][j-1] + p[i-1][j]因为只使用了相邻层,因此可以压缩状态空间代码: 1 vector getRow(int rowIndex) { 2 if... 阅读全文
posted @ 2015-02-02 15:20 李舜阳 阅读(113) 评论(0) 推荐(0)
摘要:原题地址基本模拟题代码: 1 vector > generate(int numRows) { 2 vector > res; 3 4 if (numRows (1, 1)); 8 while (--numRows) { 9 ... 阅读全文
posted @ 2015-02-02 14:08 李舜阳 阅读(124) 评论(0) 推荐(0)
摘要:原题地址基本模拟代码: 1 ListNode *removeNthFromEnd(ListNode *head, int n) { 2 ListNode *fast = head; 3 ListNode *slow = head; 4 ListNode... 阅读全文
posted @ 2015-02-02 14:01 李舜阳 阅读(104) 评论(0) 推荐(0)
摘要:原题地址注意空树即使sum=0也不算代码: 1 bool solve(TreeNode *root, int sum) { 2 if (!root->left && !root->right) 3 return sum == root->val; 4 5 return (root-... 阅读全文
posted @ 2015-02-02 12:05 李舜阳 阅读(123) 评论(0) 推荐(0)
摘要:原题地址基本二叉树遍历代码:1 int minDepth(TreeNode *root) {2 if (!root)3 return 0;4 5 int l = root->left ? minDepth(root->l... 阅读全文
posted @ 2015-02-02 11:47 李舜阳 阅读(101) 评论(0) 推荐(0)
摘要:原题地址参考了这篇博文的想法代码: 1 int balancedp(TreeNode *root) { 2 if (!root) 3 return 0; 4 5 int l = balancedp(root->left); 6 int r = balancedp(root->r... 阅读全文
posted @ 2015-02-02 11:38 李舜阳 阅读(152) 评论(0) 推荐(0)
摘要:原题地址二叉树层次遍历,最后把遍历结果翻转一下即可代码: 1 vector > levelOrderBottom(TreeNode *root) { 2 vector > res; 3 queue layer; 4 5 layer.p... 阅读全文
posted @ 2015-02-02 11:16 李舜阳 阅读(204) 评论(0) 推荐(0)
摘要:原题地址二叉树的遍历代码:1 int maxDepth(TreeNode *root) {2 if (!root)3 return 0;4 return max(maxDepth(root->left), maxDepth(root->righ... 阅读全文
posted @ 2015-02-02 11:11 李舜阳 阅读(142) 评论(0) 推荐(0)
摘要:原题地址二叉树的层次遍历代码: 1 vector > levelOrder(TreeNode *root) { 2 vector > res; 3 queue layer; 4 5 layer.push(root); 6 ... 阅读全文
posted @ 2015-02-02 11:09 李舜阳 阅读(138) 评论(0) 推荐(0)
摘要:原题地址递归比较左儿子和右儿子是否对称,左儿子的左儿子跟右儿子的右儿子比,左儿子的右儿子跟右儿子的左儿子比!打完这一串文字突然发现"儿"字怎么这么奇怪!代码: 1 bool mirrorp(TreeNode *a, TreeNode *b) { 2 if (a && b) 3 retur... 阅读全文
posted @ 2015-02-02 11:04 李舜阳 阅读(202) 评论(0) 推荐(0)
摘要:原题地址基本模拟题代码:1 bool isSameTree(TreeNode *p, TreeNode *q) {2 if (p && q)3 return p->val == q->val && isSameTree(p->left, q->left) &&... 阅读全文
posted @ 2015-02-02 10:55 李舜阳 阅读(134) 评论(0) 推荐(0)
摘要:原题地址基本模拟题代码: 1 int removeDuplicates(int A[], int n) { 2 if (n <= 0) 3 return 0; 4 5 int i = 1; 6 int ... 阅读全文
posted @ 2015-02-02 10:51 李舜阳 阅读(128) 评论(0) 推荐(0)
摘要:原题地址基本模拟题,双指针法代码: 1 int removeElement(int A[], int n, int elem) { 2 int i = 0; 3 int j = 0; 4 5 while (i < n) { 6 ... 阅读全文
posted @ 2015-02-02 10:47 李舜阳 阅读(134) 评论(0) 推荐(0)
摘要:原题地址基本模拟,记得最后把尾节点next置为NULL...代码: 1 ListNode *deleteDuplicates(ListNode *head) { 2 ListNode *h = NULL; 3 ListNode *t = NULL; 4 ... 阅读全文
posted @ 2015-02-02 10:42 李舜阳 阅读(134) 评论(0) 推荐(0)
摘要:原题地址基本动归题可以压缩状态空间代码: 1 int climbStairs(int n) { 2 if (n <= 0) 3 return 0; 4 5 int count = 1; 6 int tm... 阅读全文
posted @ 2015-02-02 10:33 李舜阳 阅读(148) 评论(0) 推荐(0)
摘要:原题地址简单模拟代码: 1 vector plusOne(vector &digits) { 2 vector sum(digits.size(), 0); 3 int carry = 1; 4 5 for (int i = digi... 阅读全文
posted @ 2015-02-02 10:19 李舜阳 阅读(197) 评论(0) 推荐(0)
摘要:原题地址按照数独规则判断即可代码: 1 bool isValidSudoku(vector > &board) { 2 unordered_set record; 3 4 for (int i = 0; i < 9; i++) { 5 ... 阅读全文
posted @ 2015-02-02 10:10 李舜阳 阅读(172) 评论(0) 推荐(0)
摘要:原题地址简单模拟题代码: 1 string addBinary(string a, string b) { 2 int i = a.length() - 1; 3 int j = b.length() - 1; 4 int carry = 0; 5 ... 阅读全文
posted @ 2015-02-02 09:43 李舜阳 阅读(155) 评论(0) 推荐(0)
摘要:原题地址链表归并排序的一个小函数代码: 1 ListNode *mergeTwoLists(ListNode *l1, ListNode *l2) { 2 ListNode *h = NULL; 3 ListNode *t = NULL; 4 5 ... 阅读全文
posted @ 2015-02-02 09:28 李舜阳 阅读(113) 评论(0) 推荐(0)
摘要:原题地址简单模拟题代码: 1 int lengthOfLastWord(const char *s) { 2 char prev = ' '; 3 int length = 0; 4 5 while (*s) { 6 ... 阅读全文
posted @ 2015-02-02 09:23 李舜阳 阅读(154) 评论(0) 推荐(0)
摘要:原题地址简单模拟题从1开始推即可。不知道有没有规律可以直接求出n代码: 1 string countAndSay(int n) { 2 if (n <= 0) 3 return ""; 4 5 string str =... 阅读全文
posted @ 2015-02-02 09:13 李舜阳 阅读(151) 评论(0) 推荐(0)
摘要:原题地址方法I,DFS一边遍历一边复制借助辅助map保存已经复制好了的节点对于原图中每个节点,如果已经复制过了,直接返回新节点的地址,如果没复制过,则复制并加入map中,接着依次递归复制其兄弟。代码: 1 map old2new; 2 3 UndirectedGraphNode *cloneGra... 阅读全文
posted @ 2015-02-01 22:55 李舜阳 阅读(231) 评论(0) 推荐(0)
摘要:原题地址因为要找所有的解,只能搜索+回溯了看来数据量比较小,关于回文串的判断没有使用动态规划也可以过代码: 1 vector > res; 2 3 bool palindromep(string s) { 4 int i = 0; 5 int j = s.length() - 1; 6 ... 阅读全文
posted @ 2015-02-01 22:16 李舜阳 阅读(355) 评论(0) 推荐(0)
摘要:原题地址二叉树的遍历代码: 1 vector path; 2 3 int sumNumbers(TreeNode *root) { 4 if (!root) 5 return 0; 6 7 int sum =... 阅读全文
posted @ 2015-02-01 22:06 李舜阳 阅读(115) 评论(0) 推荐(0)
摘要:原题地址跟2sum、3sum、4sum、3sum closest一系列,参见这篇文章排序+DFS+剪枝+二分查找如果最后一个元素不二分查找会超时??代码: 1 vector > res; 2 3 void dfs(vector &num, vector ans, int pos, int left... 阅读全文
posted @ 2015-02-01 21:36 李舜阳 阅读(199) 评论(0) 推荐(0)