DFS
i-Blue
抱平常心走平常路
展开
-
POJ 3687 Labeling Balls-拓扑排序
题目:DescriptionWindy has N balls of distinct weights from 1 unit to N units. Now he tries to label them with 1 to N in such a way that:No two balls share the same label.The labeling sat原创 2016-06-18 17:14:04 · 327 阅读 · 0 评论 -
131. Palindrome Partitioning
回文分割。DP+dfs。先判断str中任意字串是否是回文,用动态规划方法://construct the pailndrome checking matrix// 1) matrix[i][j] = true; if (i==j) -- only one char// 2) matrix[i][j] = true; if (i==j+1) && s[i]==s[j] -- o原创 2016-08-16 00:49:37 · 387 阅读 · 0 评论 -
100. Same Tree
Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value.题目判断两个bina原创 2016-10-12 21:28:43 · 228 阅读 · 0 评论 -
235. Lowest Common Ancestor of a Binary Search Tree--dfs
Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined betw原创 2016-10-24 22:03:36 · 273 阅读 · 0 评论 -
437. Path Sum III--dfs + hash + 连续序列的和等于给定的数num
You are given a binary tree in which each node contains an integer value.Find the number of paths that sum to a given value.The path does not need to start or end at the root or a leaf, but it原创 2016-10-27 19:48:22 · 1613 阅读 · 0 评论 -
101. Symmetric Tree--DFS(递归)/BFS(queue+迭代)
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree [1,2,2,3,4,4,3] is symmetric: 1 / \ 2 2 / \ / \3 4 4 3原创 2016-11-02 17:44:33 · 482 阅读 · 0 评论