原创 LRU Cache的C++實現

方法一:雙鏈表+哈希表map #include<iostream> #include<map> using namespace std; struct Node { int key; int value;

原创 【leetcode】Populating Next Right Pointers in Each Node II

#include<iostream> #include<vector> #include<deque> #include<stack> using namespace std; struct TreeNode { int

原创 【leetcode】Flatten Binary Tree to Linked List

前序遍歷二叉樹,並進行扁平化處理 #include<iostream> #include<vector> #include<deque> #include<stack> using namespace std; struct Tr

原创 【leetcode】Same Tree和Balanced Binary Tree

#include<iostream> #include<vector> #include<deque> using namespace std; struct TreeNode { int val; TreeNod

原创 [leetcode] Binary Tree Zigzag Level Order Traversal

#include<iostream> #include<list> #include<queue> #include<vector> using namespace std; struct TreeNode { int

原创 【leetcode】 Anagrams

代碼1: #include<iostream> #include<string> #include<vector> #include<algorithm> #include<map> using namespace std;

原创 Wildcard Matching

迭代: #include<iostream> using namespace std; class Solution { public: bool isMatch(const char *s, const char *p)

原创 Morris遍歷二叉樹

#include<iostream> #include<list> using namespace std; struct TreeNode { int value; TreeNode* left; Tr

原创 【leetcode】Construct Binary Tree from Preorder and Inorder Traversal

#include<iostream> #include<vector> #include<map> using namespace std; struct TreeNode { int val; TreeNode

原创 Recover Binary Search Tree

#include<iostream> #include<vector> using namespace std; struct TreeNode { int val; TreeNode* left; Tre

原创 面試題目積累

19.C++多態的實現原理 對於虛函數調用來說,每一個對象內部都有一個虛表指針,該虛表指針被初始化爲本類的虛表。所以在程序中,不管你的對象類型如何轉換,但該對象內部的虛表指針是固定的,所以呢,才能實現動態的對象函數調用,這就是C

原创 Validate Binary Search Tree

題目要求判斷一顆二叉樹是否是有效的二叉搜索樹 #include<iostream> #include<vector> using namespace std; struct TreeNode { int val;

原创 [leetcode]Binary Tree Level Order Traversal II

#include<iostream> #include<list> #include<queue> #include<vector> using namespace std; struct TreeNode { int

原创 【leetcode】Largest Rectangle in Histogram

#include<iostream> #include<vector> using namespace std; class Solution { public: int fun(vector<int> a) {

原创 [leetcode]Unique Binary Search Trees II

#include<iostream> #include<vector> using namespace std; struct TreeNode { int val; TreeNode* left; Tre