上一页 1 2 3 4 5 6 7 ··· 10 下一页
摘要: Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.---/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) ... 阅读全文
posted @ 2013-09-23 03:45 LEDYC 阅读(156) 评论(0) 推荐(1)
摘要: Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees ofeverynode never differ by more than 1.---/** * Definition for binary tree * public class TreeNode { * int val; * TreeNo... 阅读全文
posted @ 2013-09-23 03:32 LEDYC 阅读(169) 评论(0) 推荐(1)
摘要: Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.---需要总长度,遍历一遍,1. 可以再这个时候吧list转成array, 费地方2. 或者跟array一样每次走半个长度找到mid, O(NlogN), logN层,每层遍历N,费时间/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode n... 阅读全文
posted @ 2013-09-23 02:57 LEDYC 阅读(184) 评论(0) 推荐(1)
摘要: Given an array where elements are sorted in ascending order, convert it to a height balanced BST.---/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */public class Solution { public TreeNode... 阅读全文
posted @ 2013-09-23 02:53 LEDYC 阅读(121) 评论(0) 推荐(1)
摘要: Given a binary tree, return thebottom-up level ordertraversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For example:Given binary tree{3,9,20,#,#,15,7}, 3 / \ 9 20 / \ 15 7return its bottom-up level order traversal as:[ [15,7] [9,20], [3],]conf... 阅读全文
posted @ 2013-09-23 02:42 LEDYC 阅读(139) 评论(0) 推荐(1)
摘要: 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)
上一页 1 2 3 4 5 6 7 ··· 10 下一页