原创 搜索策略及優化

暴力搜索 枚舉所有可能的結果進行搜索,地毯式搜索。 廣度優先BFS 1.構造由根組成的隊列Q 2.如果Q的第一個元素是目標節點,那麼就停止搜索 3.從Q中刪除元素x,並把x的所以子節點加入到隊列的末尾 4.如果Q爲空,則

原创 + - 與>>

+、-運算符的優先級高於<< >>位移運算符 int mian() { int a=2,b=4; cout<<"a+b>>1="<<(a+b>>1)<<endl; cout<<"a+(b>>1)="<<(a

原创 C++ queue 隊列

queue queue是模板類,定義在 < queue > 頭文件裏面。 template < class T, class Container = deque<T> > class queue; T: Type of th

原创 117. Populating Next Right Pointers in Each Node II

/* Follow up for problem "Populating Next Right Pointers in Each Node". What if the given tree could be any binar

原创 116. Populating Next Right Pointers in Each Node

/* Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeL

原创 129_sumRoottoLeafNumbers

/* Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number. An examp

原创 226. Invert Binary Tree

/* Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \

原创 199. Binary Tree Right Side View

/* Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can

原创 124_binaryTreeMaximumPathSum

/* Given a binary tree, find the maximum path sum. For this problem, a path is defined as any sequence of nodes f

原创 236. Lowest Common Ancestor of a Binary Tree

/* Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. According to the def

原创 235. Lowest Common Ancestor of a Binary Search Tree

/* Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST. Accordi

原创 113. Path Sum II

/* Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum. For exa

原创 450. Delete Node in a BST

/* Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return the root n

原创 222. Count Complete Tree Nodes

/* Given a complete binary tree, count the number of nodes. Definition of a complete binary tree from Wikipedia:

原创 515. Find Largest Value in Each Tree Row

/* You need to find the largest value in each row of a binary tree. Example: Input: 1 / \