04 2013 档案

Short term goal for 2013 rest time
摘要:1. Sleep before 12:00 pm, get up before 8:am every day [0/10]2. GPA reaches 3.88 after 6 courses [Achieved]3. Finish the thesis during the summer [In Porgress...] 4. Find a great advisor towards Phd [In Progress...][new 07/15/2013]5. Prepare for the basic coding problems(LeetCode 63/132, Project... 阅读全文

posted @ 2013-04-26 23:13 freeneng 阅读(105) 评论(0) 推荐(0)

[Leetcode 16] 9 Palindrome Number
摘要: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)

[Leetcode 15] 8 String to Integer (atoi)
摘要: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 阅读(681) 评论(0) 推荐(0)

[Leetcode 14] 7 Reverse Integer
摘要: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)

[Leetcode 13] 1 Two Sum
摘要: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 阅读(155) 评论(0) 推荐(0)

[Leetcode 12] 126 Word Ladder II TO_BE_ADDED
摘要:Problem:Analysis:Code:Attention: 阅读全文

posted @ 2013-04-10 13:12 freeneng 阅读(193) 评论(0) 推荐(0)

[Leetcode 11] 112 Path Sum
摘要: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 阅读(191) 评论(0) 推荐(0)

[Leetcode 10] 111 Minimum Depth of Binary Tree
摘要: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 阅读(186) 评论(0) 推荐(0)

[Leetcode 9] 110 Balanced Binary Tree
摘要: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 阅读(146) 评论(0) 推荐(0)

[Leetcode 8] 104 Maximum Depth of Binary Tree
摘要: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 阅读(161) 评论(0) 推荐(0)

[Leetcode 7] 101 Symmetric Tree
摘要: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)

[Leetcode 6] 100 Same Tree
摘要:Problem:Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value.Analysis:Use a queue to do level order traversal is not proper in this problem since this method ignores the s 阅读全文

posted @ 2013-04-07 08:10 freeneng 阅读(184) 评论(0) 推荐(0)

[Leetcode 5] 83 Remove Duplicates from Sorted List
摘要:Problem:Given a sorted linked list, delete all duplicates such that each element appear onlyonce.For example,Given1->1->2, return1->2.Given1->1->2->3->3, return1->2->3.Analysis:It's similar to the remove duplicates from sorted array problem. Use pointers ptrA and ptrB. 阅读全文

posted @ 2013-04-07 07:34 freeneng 阅读(170) 评论(0) 推荐(0)

[Leetcode 4] 66 Plus One
摘要:Problem:Given a number represented as an array of digits, plus one to the number.Analysis:The given array represents number from the greatest position to least position, so addition must start from the end of the array;When adding 1 to the number, there're two situations: 1. the digit is 9, then 阅读全文

posted @ 2013-04-06 14:28 freeneng 阅读(334) 评论(0) 推荐(0)

[Leetcode 3] 58 Length of Last Word
摘要:Problem:Given a stringsconsists of upper/lower-case alphabets and empty space characters' ', return the length of last word in the string.If the last word does not exist, return 0.Note:A word is defined as a character sequence consists of non-space characters only.For example,Givens="He 阅读全文

posted @ 2013-04-06 13:52 freeneng 阅读(257) 评论(0) 推荐(0)

[Leetcode 2] 27 Remove Element
摘要:Problem:Given an array and a value, remove all instances of that value in place and return the new length.The order of elements can be changed. It doesn't matter what you leave beyond the new length.Analysis:Use two pointers, ptrA points to the next-valid-to-copy place; ptrB go through the input 阅读全文

posted @ 2013-04-06 13:30 freeneng 阅读(163) 评论(0) 推荐(0)

[Leetcode 1] 26 Remove Duplicates from Sorted Array
摘要:Problem:Given a sorted array, remove the duplicates in place such that each element appear onlyonceand return the new length.Do not allocate extra space for another array, you must do this in place with constant memory.For example,Given input array A =[1,1,2],Your function should return length =2, a 阅读全文

posted @ 2013-04-06 13:04 freeneng 阅读(122) 评论(0) 推荐(0)

导航