从上往下打印二叉树

摘要: /* struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) { } };*/ class Solution { public: ve... 阅读全文
posted @ 2017-03-01 18:05 123_123 阅读(139) 评论(0) 推荐(0) 编辑

合并两个有序链表

摘要: /* struct ListNode { int val; struct ListNode *next; ListNode(int x) : val(x), next(NULL) { } };*/ class Solution { public: ListNode* Merge(ListNode* pHead1, ListNode*... 阅读全文
posted @ 2017-03-01 18:00 123_123 阅读(129) 评论(0) 推荐(0) 编辑

翻转单链表

摘要: /* struct ListNode { int val; struct ListNode *next; ListNode(int x) : val(x), next(NULL) { } };*/ class Solution { public: ListNode* ReverseList(ListNode... 阅读全文
posted @ 2017-03-01 17:59 123_123 阅读(83) 评论(0) 推荐(0) 编辑

链表中倒数第k个结点

摘要: /* struct ListNode { int val; struct ListNode *next; ListNode(int x) : val(x), next(NULL) { } };*/ class Solution { public: ListNode* FindKthToTail(ListNo... 阅读全文
posted @ 2017-03-01 17:59 123_123 阅读(95) 评论(0) 推荐(0) 编辑

1+2+3+....+n

摘要: class Solution { public: int Sum_Solution(int n) { return (long(1)+n)*n/2; } }; 阅读全文
posted @ 2017-03-01 01:24 123_123 阅读(113) 评论(0) 推荐(0) 编辑

用两个栈实现队列

摘要: class Solution { public: void push(int node) { stack1.push(node); } int pop() { int res = 0; if(!stack2.empty()) { res =... 阅读全文
posted @ 2017-03-01 01:23 123_123 阅读(82) 评论(0) 推荐(0) 编辑

二进制中1的个数

摘要: class Solution { public: int NumberOf1(int n) { int count = 0; while(n) { ++count; n = (n-1)&n; } return ... 阅读全文
posted @ 2017-03-01 01:23 123_123 阅读(61) 评论(0) 推荐(0) 编辑

二叉树的镜像

摘要: 题目描述 操作给定的二叉树,将其变换为源二叉树的镜像。 输入描述: 二叉树的镜像定义:源二叉树 8 / \ 6 10 / \ / \ 5 7 9 11 镜像二叉树 8 / \ 10 6 / \ / \ 11 9 7 5 class Solution { public: void Mirror(Tre 阅读全文
posted @ 2017-03-01 01:22 123_123 阅读(70) 评论(0) 推荐(0) 编辑

斐波那契数列非递归算法

摘要: class Solution { public: int Fibonacci(int n) { int res[2] = {0,1}; if(n<=1) return res[n]; int num1 = 1; int num2 = 0; ... 阅读全文
posted @ 2017-03-01 01:22 123_123 阅读(165) 评论(0) 推荐(0) 编辑

不用加减乘除做加法

摘要: class Solution { public: int Add(int num1, int num2) { if(num1 == 0) return num2; if(num2 == 0) return num1; i... 阅读全文
posted @ 2017-03-01 01:21 123_123 阅读(94) 评论(0) 推荐(0) 编辑