摘要: Problem: With the 2010 FIFA World Cup running, football fans the world over were becoming increasingly excited as the best players from the best teams 阅读全文
posted @ 2020-10-05 19:11 tao10203 阅读(130) 评论(0) 推荐(0)
摘要: Problem: The highest building in our city has only one elevator. A request list is made up with N positive numbers. The numbers denote at which floors 阅读全文
posted @ 2020-10-05 18:43 tao10203 阅读(132) 评论(2) 推荐(1)
摘要: settings.json里面加入 "C_Cpp.clang_format_style": { BasedOnStyle: Google, IndentWidth: 4} 添加之后的效果 阅读全文
posted @ 2020-10-05 15:44 tao10203 阅读(1529) 评论(0) 推荐(0)
摘要: Problem: Calculate a+b and output the sum in standard format -- that is, the digits must be separated into groups of three by commas (unless there are 阅读全文
posted @ 2020-10-04 18:20 tao10203 阅读(197) 评论(0) 推荐(0)
摘要: 题目 请实现一个函数,把字符串 s 中的每个空格替换成"%20"。要求:空间复杂度 O(1) 示例 1: 输入:s = "We are happy."输出:"We%20are%20happy." 限制: 0 <= s 的长度 <= 10000 思路 题目要求空间复杂度为O(1),所以不能通过新建字符 阅读全文
posted @ 2020-10-04 15:58 tao10203 阅读(126) 评论(0) 推荐(0)
摘要: 题目 在一个 n * m 的二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。 示例: 现有矩阵 matrix 如下: [ [1, 4, 7, 11, 15], [2, 5, 8, 12, 阅读全文
posted @ 2020-09-28 20:03 tao10203 阅读(213) 评论(0) 推荐(0)
摘要: 算法思路 我们遍历整颗二叉树,定义F(x)表示x节点的子树或本身是否包含p节点或q节点,如果包含即为true。那么符合条件的最近公共祖先x一定满足如下条件: F(x->lchild)&&F(x->rchild) || ((x=p||x=q)&&F(x->lchild)||F(x->rchild)) 阅读全文
posted @ 2020-09-27 23:19 tao10203 阅读(455) 评论(0) 推荐(0)
摘要: 题目: 用单链表实现一元稀疏多项式的加、减运算。 算法思想 设p,q分别指向A,B中某一结点,p,q初值是第一结点,则: 代码 #include<stdio.h> #include <stdlib.h> using namespace std; typedef struct Pnode { // 项 阅读全文
posted @ 2020-09-26 20:15 tao10203 阅读(474) 评论(0) 推荐(1)
摘要: 算法思想 最大公约数gcd:辗转相除法,最小公倍数lcm:易证当d=gcd(a,b)时,lcm(a,b)=a*b/d,由于先计算ab有可能出现溢出,所以更安全的写法是a/d*b //a>b否则交换a,b int gcd(int a,int b){ if(b==0)return a; else ret 阅读全文
posted @ 2020-09-25 10:32 tao10203 阅读(76) 评论(0) 推荐(0)
摘要: 算法思想 后序遍历序列的最后一个节点是根节点,而中序遍历的根节点左侧都是左子树的节点,右侧都是右子树的节点,根据这种特点,我们可以从后序遍历中找到根节点,再在中序遍历中找到根节点,然后递归的对中序遍历的左子树及右子树进行建树; C++代码 struct TreeNode { int val; Tre 阅读全文
posted @ 2020-09-25 09:57 tao10203 阅读(422) 评论(0) 推荐(0)