发布时间:2015-03-05 09:16:01
Write a function to find the longest common prefix string amongst an array of strings.public class LongestCommonPrefix {public String longestCommonPrefix(String[] strs) {if(strs.length==0)return "";String tempString=strs[0]; for (int i = 1; i < strs.length; i++) { i.........【阅读全文】
发布时间:2015-01-30 12:35:29
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?二叉排序树中有两个节点被交换了,要求把树恢复成二叉排序树。中序遍历二叉树生.........【阅读全文】
发布时间:2015-01-29 12:39:56
/You are given an n x n 2D matrix representing an image.////Rotate the image by 90 degrees (clockwise).////Follow up://Could you do this in-place?矩阵旋转问题:先对正对角线轴对称,在对垂直最中间的线轴对称。public class RotateImage {public void rotate(int[][] matrix) {int row=matrix.length.........【阅读全文】
发布时间:2014-12-05 18:00:24
Word BreakGiven 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.For example, givens = "leetcode",dict = ["leet", "code"].Return true because "l.........【阅读全文】
发布时间:2014-11-18 13:17:13
非递归实现 后序遍历的非递归实现是三种遍历方式中最难的一种。因为在后序遍历中,要保证左孩子和右孩子都已被访问并且左孩子在右孩子前访问才能访问根结点,这就为流程的控制带来了难题。下面介绍两种思路。 第一种思路:对于任一结点P.........【阅读全文】