上一页 1 ··· 6 7 8 9 10 11 下一页

2013年4月21日

摘要: Problem:Determine whether an integer is a palindrome. Do this without extra space.Analysis:One tricky way to do this is to convert it into string and then use the normal palindrome way to solve the problem. Though it violates the requirement of "no extra space", the online judger won't 阅读全文
posted @ 2013-04-21 15:09 freeneng 阅读(164) 评论(0) 推荐(0) 编辑

2013年4月15日

摘要: Problem:Implementatoito convert a string to an integer.Hint:Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input cases.Notes:It is intended for this problem to be specified vaguely (ie, no given input specs). You a 阅读全文
posted @ 2013-04-15 14:55 freeneng 阅读(679) 评论(0) 推荐(0) 编辑

2013年4月11日

摘要: Problem:Reverse digits of an integer.Example1:x = 123, return 321Example2:x = -123, return -321Analysis:It's the basic conversion problem. The only thing to note is that keep the negative number as negative and positive as positive.Code:View Code 1 public class Solution { 2 public int reverse(i. 阅读全文
posted @ 2013-04-11 15:18 freeneng 阅读(387) 评论(0) 推荐(0) 编辑

2013年4月10日

摘要: Problem:Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up to the target, where index1 must be less than index2. Please note that your returned answers (both index1 and inde 阅读全文
posted @ 2013-04-10 13:21 freeneng 阅读(154) 评论(0) 推荐(0) 编辑
摘要: Problem:Analysis:Code:Attention: 阅读全文
posted @ 2013-04-10 13:12 freeneng 阅读(191) 评论(0) 推荐(0) 编辑
摘要: Problem:Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.For example:Given the below binary tree andsum = 22, 5 / \ 4 8 / / \ 11 13 4 ... 阅读全文
posted @ 2013-04-10 12:27 freeneng 阅读(188) 评论(0) 推荐(0) 编辑
摘要: Problem: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.Analysis:This problem is quite easy. When we compute the height of a binary tree, we use 1 + max(left_height, right_height) recursivly 阅读全文
posted @ 2013-04-10 09:37 freeneng 阅读(185) 评论(0) 推荐(0) 编辑
摘要: Problem: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.Analysis:This problem is different from the 4.1 problem in Cracking the Code Inte 阅读全文
posted @ 2013-04-10 09:19 freeneng 阅读(142) 评论(0) 推荐(0) 编辑

2013年4月7日

摘要: Problem: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.Analysis:Recursion can solve it.The time complexity is O(h).Code:View Code 1 /** 2 * Definition for binary tree 3 * public class Tr... 阅读全文
posted @ 2013-04-07 10:43 freeneng 阅读(160) 评论(0) 推荐(0) 编辑
摘要: Problem: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 3Analysis:Recursion can help in this problem. Write a helper ... 阅读全文
posted @ 2013-04-07 08:49 freeneng 阅读(453) 评论(0) 推荐(0) 编辑
上一页 1 ··· 6 7 8 9 10 11 下一页

导航