摘要: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...
阅读全文
摘要: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
阅读全文
摘要: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
阅读全文
摘要: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.
阅读全文
摘要: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
阅读全文
摘要:Problem:Analysis:Code:Attention:
阅读全文
摘要: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 ...
阅读全文
摘要: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
阅读全文
摘要: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
阅读全文
摘要: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...
阅读全文
摘要: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 ...
阅读全文
摘要: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
阅读全文
摘要: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.
阅读全文
摘要: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
阅读全文
摘要: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
阅读全文
摘要: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
阅读全文
摘要: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
阅读全文