leetcode刷题
ningbupt
责任、梦想
展开
-
Populating Next Right Pointers in Each Node II
一开始用递归,发现有些条件不满足,后来用队列的方法就accept了。/** * Definition for binary tree with next pointer. * public class TreeLinkNode { * int val; * TreeLinkNode left, right, next; * TreeLinkNode(int原创 2013-10-13 08:55:33 · 1077 阅读 · 0 评论 -
Maximum Depth of Binary Tree
/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */public class Solution {原创 2013-10-16 09:41:03 · 1091 阅读 · 0 评论 -
Minimum Depth of Binary Tree
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 bina原创 2013-10-16 09:38:35 · 1067 阅读 · 0 评论 -
word break
Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words.以下是网上的解法,太巧妙了。class Solution { public原创 2013-10-16 21:40:41 · 1169 阅读 · 0 评论 -
Write a function to find the longest common common string amongst an array of strings.
这个算法我是求的公共子序列,而不是公共前缀。提交到online不会通过。public class Solution { public String longestCommonPrefix(String[] strs) { // Note: The Solution object is instantiated only once and is reused by eac原创 2013-10-13 16:04:14 · 1294 阅读 · 0 评论