分治
HELLO_蓝猫
这个作者很懒,什么都没留下…
展开
-
Leetcode 90. Subsets II
class Solution { public: bool equal(vector<int> cur, vector<int> last) //等于false才可以 { if (cur.size() != last.size())return false; for (int i = 0; i < cur.size(); i++) { if (...原创 2018-03-22 14:22:05 · 105 阅读 · 0 评论 -
Leetcode 108. Convert Sorted Array to Binary Search Tree
解法:永远以中点为根,左右划分,之后递归。将一个按照升序排列的有序数组,转换为一棵高度平衡二叉搜索树。本题中,一个高度平衡二叉树是指一个二叉树每个节点 的左右两个子树的高度差的绝对值不超过 1。示例:给定有序数组: [-10,-3,0,5,9], 一个可能的答案是:[0,-3,9,-10,null,5],它可以表示下面这个高度平衡二叉搜索树: 0 / \ -3 ...原创 2018-04-26 16:51:57 · 116 阅读 · 0 评论 -
Leetcode 106. Construct Binary Tree from Inorder and Postorder Traversal
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ class Solution { //和上一...原创 2018-04-25 19:18:03 · 159 阅读 · 0 评论 -
Leetcode 105. Construct Binary Tree from Preorder and Inorder Traversal
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ class Solution { publ...原创 2018-04-25 16:56:37 · 93 阅读 · 0 评论 -
Leetcode 101. Symmetric Tree
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ clas...原创 2018-04-25 15:18:30 · 133 阅读 · 0 评论 -
Leetcode 103. Binary Tree Zigzag Level Order Traversal
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ cla...原创 2018-04-20 16:23:55 · 83 阅读 · 0 评论 -
Leetcode 102. Binary Tree Level Order Traversal
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ clas...原创 2018-04-20 15:22:38 · 97 阅读 · 0 评论 -
Leetcode 104. Maximum Depth of Binary Tree
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ clas...原创 2018-04-18 11:05:04 · 106 阅读 · 0 评论 -
Leetcode 98. Validate Binary Search Tree
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ class Solution { int...原创 2018-03-29 16:07:04 · 104 阅读 · 0 评论 -
Leetcode 100. Same Tree
Given two binary trees, write a function to check if they are the same or not.Two binary trees are considered the same if they are structurally identical and the nodes have the same value.Example 1:In...原创 2018-04-02 13:26:35 · 92 阅读 · 0 评论 -
邮局问题 快速排序 分治
// 邮局选址问题.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include <iostream> #include <algorithm> #include <string> #include <vector> #include <fstream> #include <memory..原创 2018-04-02 10:58:00 · 1117 阅读 · 0 评论 -
Leetcode 95. Unique Binary Search Trees II
解法:二叉搜素树,想法是,把每一个数当根结点,然后去划分左右子树,最开始没有想好如何去吧结果放到数组中,只关注如何区分左右子书,重写方法,还是同样的类型,用来算每个节点的可能性,每个点都可能,然后保留当前点,左右划分,分完之后,不能划分只有两种,一种只有一个,一种是null,排列组合所有左右节点可能,放到ans。/** * Definition for a binary tree node. ...原创 2018-03-25 16:16:05 · 90 阅读 · 0 评论 -
Leetcode 79. Word Search
79. Word SearchDescriptionHintsSubmissionsDiscussSolutionPick OneGiven a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell...原创 2018-03-09 11:26:46 · 101 阅读 · 0 评论 -
Leetcode 77. Combinations
class Solution { public: void DFS(int left, int right, int count, vector<int> &temp, vector<vector<int>> &ans) { //开始位置 结束位置 还需要组合的个数 两个答案 for (int i = left; i &l...原创 2018-03-01 11:31:26 · 138 阅读 · 0 评论 -
Leetcode 89. Gray Code
class Solution { public: vector<vector<int>> gray(int n) { if (n == 1) { return{ {0} ,{1} }; } else { vector<vector<int>> v = gray(n-1); vector...原创 2018-03-22 11:45:56 · 119 阅读 · 0 评论 -
Leetcode 109. Convert Sorted List to Binary Search Tree
/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */ /** * Definition for a binary tree node. * pub...原创 2018-05-04 14:06:35 · 118 阅读 · 0 评论