摘要: Given a string containing just the characters'('and')', find the length of the longest valid (well-formed) parentheses substring.For"(()", the longest valid parentheses substring is"()", which has length = 2.Another example is")()())", where the longest 阅读全文
posted @ 2013-09-22 12:20 LEDYC 阅读(134) 评论(0) 推荐(0)
摘要: Write a program to solve a Sudoku puzzle by filling the empty cells.Empty cells are indicated by the character'.'.You may assume that there will be only one unique solution.A sudoku puzzle......and its solution numbers marked in red.--- public boolean solveSudoku(char[][] board) { ... 阅读全文
posted @ 2013-09-22 11:52 LEDYC 阅读(151) 评论(0) 推荐(0)
摘要: Determine if a Sudoku is valid, according to:Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are filled with the character'.'.A partially filled sudoku which is valid.---public class Solution { public boolean isValidSudoku(char[][] board) { int n = .. 阅读全文
posted @ 2013-09-22 11:50 LEDYC 阅读(153) 评论(0) 推荐(0)
摘要: Given a collection of candidate numbers (C) and a target number (T), find all unique combinations inCwhere the candidate numbers sums toT.Each number inCmay only be usedoncein the combination.Note:All numbers (including target) will be positive integers.Elements in a combination (a1,a2, � ,ak) must 阅读全文
posted @ 2013-09-22 11:27 LEDYC 阅读(161) 评论(0) 推荐(0)
摘要: Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.---跟50 -Queue思路一样问题是那个不能用int total带入,而是int[] 即便是一位数组,如果只是int作为参数,只是copy the value to the function, total本身没有变,如果是int[], 相当吧variable's reference带入, 可以改变参数本身的值,试过 Integer,也不行, 阅读全文
posted @ 2013-09-22 06:02 LEDYC 阅读(167) 评论(0) 推荐(0)
摘要: 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)