
数据结构与算法
天花板上飞着鱼
这个作者很懒,什么都没留下…
展开
-
回溯算法
39.组合搜索、回溯问题的套路是画图,代码是根据树形图写出来的。class Solution {public: void backtracking(vector<vector<int>>& res,vector<int>& candidates,vector<int>subset,int target,int ...原创 2020-01-06 15:25:03 · 154 阅读 · 0 评论 -
面试题16:数值的整数次方
题目:实现函数double Power(double base, int exponent),求base的exponent的次方。不得使用库函数,同事不需要考虑大数问题。#include<iostream>#include<stdexcept>using namespace std;bool global_invalid_input = false;doub...原创 2019-07-01 10:15:34 · 146 阅读 · 0 评论 -
二叉树遍历实现(前中后层次/递归非递归)
一.前序遍历#include<iostream>#include<stack>#include<queue>using namespace std;struct BinaryTreeNode { int m_nValue; BinaryTreeNode* m_pLeft; BinaryTreeNode* m_pRight;};//递归实现...原创 2019-07-25 11:02:27 · 104 阅读 · 0 评论 -
排序
#include<iostream>#include<stack>using namespace std;struct TreeNode { int value; TreeNode* left; TreeNode* right;};//快排void quicksort(int* que, const int length) { //长度...原创 2019-07-26 10:08:15 · 116 阅读 · 0 评论 -
leetcode148 排序链表
归并排序/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution { //cut:将head...原创 2019-09-29 11:22:22 · 145 阅读 · 0 评论 -
leetcode105从前中序遍历构造二叉树
递归思路 :每一次递归都可以看成对上图的分解;1.先找树的头节点在中序的下标 即22.分别找子树的左右子树在前序和中序的下标比如上图 前序左树1-2 前序右树3-8 中序左树0-1 中序右树3-8 /** * Definition for a binary tree node. * struct TreeNode { *...原创 2019-09-29 16:21:06 · 101 阅读 · 0 评论