
Depth-first Search
文章平均质量分 74
dyllanzhou
这个作者很懒,什么都没留下…
展开
-
[Leetcode]Number of Islands
Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume原创 2015-09-01 12:38:40 · 292 阅读 · 0 评论 -
[Leetcode]Distinct Subsequences
Given a string S and a string T, count the number of distinct subsequences ofT in S.A subsequence of a string is a new string which is formed from the original string by deleting some (can be none原创 2016-01-08 10:43:05 · 310 阅读 · 0 评论 -
[Leetcode]Additive Number
Additive number is a string whose digits can form additive sequence.A valid additive sequence should contain at least three numbers. Except for the first two numbers, each subsequent number in the s原创 2015-12-02 23:22:40 · 594 阅读 · 0 评论 -
[Leetcode]N-Queens II
Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.class Solution {public: /*algorithm: DFS */ vectorgetNex原创 2015-12-15 17:22:33 · 295 阅读 · 0 评论 -
[Leetcode]N-Queens
The n-queens puzzle is the problem of placing n queens on ann×n chessboard such that no two queens attack each other.Given an integer n, return all distinct solutions to the n-queens puzzle.Ea原创 2015-12-15 16:55:08 · 268 阅读 · 0 评论 -
[Leetcode]Convert Sorted List to Binary Search Tree
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST./** * Definition for singly-linked list. * struct ListNode { * int val; * Lis原创 2015-10-12 22:03:00 · 285 阅读 · 0 评论 -
[Leetcode]Construct Binary Tree from Preorder and Inorder Traversal
Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree./** * Definition for a binary tree node. * struct Tre原创 2015-10-26 23:47:17 · 257 阅读 · 0 评论 -
[Leetcode]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 example:Given the below binary tree and sum = 22, 5 / \原创 2015-10-26 23:17:23 · 254 阅读 · 0 评论 -
[Leetcode]Perfect Squares
Given a positive integer n, find the least number of perfect square numbers (for example,1, 4, 9, 16, ...) which sum to n.For example, given n = 12, return 3 because12 = 4 + 4 + 4; given n = 13,原创 2015-09-10 18:00:28 · 477 阅读 · 0 评论 -
[Leetcode]Flatten Binary Tree to Linked List
Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattened tree should look like: 1 \原创 2015-10-11 17:04:06 · 255 阅读 · 0 评论 -
[Leetcode] 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 see ordered from top to bottom.For example:Given the following binary tree, 1原创 2015-09-06 16:41:17 · 245 阅读 · 0 评论 -
[Leetcode]Permutation Sequence
The set [1,2,3,…,n] contains a total of n! unique permutations.By listing and labeling all of the permutations in order,We get the following sequence (ie, for n = 3):"123""132""213""231""312""原创 2015-11-09 22:49:19 · 268 阅读 · 0 评论 -
[Leetcode]Sum Root to Leaf Numbers
Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.An example is the root-to-leaf path 1->2->3 which represents the number123.Find the total sum原创 2015-10-09 19:43:15 · 251 阅读 · 0 评论 -
[Leetcode]Construct Binary Tree from Inorder and Postorder Traversal
Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree./** * Definition for a binary tree node. * struct Tr原创 2015-10-24 14:44:54 · 291 阅读 · 0 评论 -
[Leetcode]Word Break
Given a string s and a dictionary of words dict, determine ifs can be segmented into a space-separated sequence of one or more dictionary words.For example, givens = "leetcode",dict = ["leet",原创 2015-11-08 16:30:34 · 328 阅读 · 0 评论 -
[Leetcode]Clone Graph
Clone an undirected graph. Each node in the graph contains a label and a list of itsneighbors.OJ's undirected graph serialization:Nodes are labeled uniquely.We use # as a separator for each原创 2015-11-05 21:25:37 · 272 阅读 · 0 评论 -
[Leetcode]Remove Invalid Parentheses
Remove the minimum number of invalid parentheses in order to make the input string valid. Return all possible results.Note: The input string may contain letters other than the parentheses ( and).原创 2016-01-14 20:14:43 · 345 阅读 · 0 评论