leetcode刷题总结一
大四狗找工作,要刷题了,leetcode上面题目比较适合面试算法类题目,也不纯粹为了蒙题,锻炼一下面试类型的思维
有N个数,其中只有一个数出现了一次,其他都是两次,找出那个数
把所有数求一下异或
求树的最大深度
递归遍历一遍
给两个树的根节点,看两棵树是否相同
两棵树同时遍历一遍
输出这个数倒过来的数
注意负数情况,模拟一下即可
Best Time to Buy and Sell Stock II:
模拟买东西卖东西赚钱
模拟即可
给定N个节点,问有多少种不同的二叉树
卡特兰数经典案例,C(2n,n) / (n+1)
判断一个链表是否含有环
从head出发,一个一次一步,一个一次两步,若相交则有环,否则走到头就结束说明没有
Binary Tree Inorder Traversal:
中序遍历
Binary Tree Preorder Traversal:
前序遍历
Populating Next Right Pointers in Each Node:
把每层的节点按从左到右顺序链接起来,最后一个节点next指向null
void connect(TreeLinkNode *root) {
if (root == NULL) return;
connect(root->left);
connect(root->right);
TreeLinkNode *l = root->left;
TreeLinkNode *r = root->right;
while (l) {
l->next = r;
l = l->right;
r = r->left;
}
}
Remove Duplicates from Sorted List:
删除相同数值的节点链表,已排好序
扫一遍,跟前一个相同就删了那个节点
给出target,求target应该插入的array的index
二分即可
经典的fbi数列
single numberI加强版,one,two,three分别代表出现的次数
int singleNumber(int A[], int n) {
int one , two , three;
one = two = three = ;
for (int i = ;i < n;i ++) {
two |= one&A[i];
one ^= A[i];
three = one & two;
one &= ~three;
two &= ~three;
}
return one;
}
经典动态规划,求最长连续序列和
去掉array中的element元素
不用额外资源,跟尾资源swap
合并两个有序链表
Convert Sorted Array to Binary Search Tree:
Remove Duplicates from Sorted Array:
Best Time to Buy and Sell Stock:
Remove Nth Node From End of List:
Best Time to Buy and Sell Stock III:
Evaluate Reverse Polish Notation:
最新文章
- Extjs 属性控件[转载]
- c#数据类型之值类型和引用类型
- iOS 设置navigationBar背景
- jQuery性能优化(转)
- DIV中TABLE居的2种方式
- hdu 1255 覆盖的面积
- 车的UML图
- linux 分割文件
- Linux常用命令及重要目录文件分析总结
- junit 单元测试 - 参数化测试
- Centos7 Nagios 搭建
- 【转】Syncthing的安装与使用
- JMeter中返回Json数据的处理方法(转)
- Linux configure,make,make install
- 002-一般处理程序(HttpHandler)
- 矩阵乘法优化DP
- pipeenv error
- python--list和tuple类型--2
- 《转》python学习(6)序列类型-字符串
- 重新来认识你的老朋友Spring框架