上一页 1 2 3 4 5 6 7 8 ··· 10 下一页
摘要: Then-queens puzzle is the problem of placingnqueens on ann�nchessboard such that no two queens attack each other.Given an integern, return all distinct solutions to then-queens puzzle.Each solution contains a distinct board configuration of then-queens' placement, where'Q'and'.'b 阅读全文
posted @ 2013-09-22 06:00 LEDYC 阅读(179) 评论(0) 推荐(0)
摘要: 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 binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */publ... 阅读全文
posted @ 2013-09-22 02:05 LEDYC 阅读(189) 评论(0) 推荐(0)
摘要: Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.---/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) ... 阅读全文
posted @ 2013-09-22 02:02 LEDYC 阅读(128) 评论(0) 推荐(0)
摘要: Given a binary tree, return thezigzag level ordertraversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).For example:Given binary tree{3,9,20,#,#,15,7}, 3 / \ 9 20 / \ 15 7return its zigzag level order traversal as:[ [3], ... 阅读全文
posted @ 2013-09-22 01:49 LEDYC 阅读(181) 评论(0) 推荐(0)
摘要: Given a binary tree, return thelevel ordertraversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree{3,9,20,#,#,15,7}, 3 / \ 9 20 / \ 15 7return its level order traversal as:[ [3], [9,20], [15,7]]confused what"{1,#,2,3}"means?> read more . 阅读全文
posted @ 2013-09-22 01:36 LEDYC 阅读(177) 评论(0) 推荐(0)
摘要: Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \3 4 4 3But the following is not: 1 / \ 2 2 \ \ 3 3Note:Bonus points if you could solve it both recursively and iterati... 阅读全文
posted @ 2013-09-22 01:29 LEDYC 阅读(141) 评论(0) 推荐(0)
摘要: 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.---/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right... 阅读全文
posted @ 2013-09-21 12:35 LEDYC 阅读(118) 评论(0) 推荐(0)
摘要: Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A solution using O(n) space is pretty straight forward. Could you devise a constant space solution?confused what"{1,#,2,3}"means?> read more on how binary tree is seria 阅读全文
posted @ 2013-09-21 12:24 LEDYC 阅读(101) 评论(0) 推荐(0)
摘要: Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only nodes with keysless thanthe node's key.The right subtree of a node contains only nodes with keysgreater thanthe node's key.Both the left and ri 阅读全文
posted @ 2013-09-21 12:19 LEDYC 阅读(144) 评论(0) 推荐(0)
摘要: Givens1,s2,s3, find whethers3is formed by the interleaving ofs1ands2.For example,Given:s1="aabcc",s2="dbbca",Whens3="aadbbcbcac", return true.Whens3="aadbbbaccc", return false.---DP---Solution1 : 2维数组public class Solution { public boolean isInterleave(String s 阅读全文
posted @ 2013-09-21 11:59 LEDYC 阅读(142) 评论(0) 推荐(0)
上一页 1 2 3 4 5 6 7 8 ··· 10 下一页