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

2013年4月7日

摘要: 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 阅读(182) 评论(0) 推荐(0) 编辑
摘要: 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 阅读(168) 评论(0) 推荐(0) 编辑

2013年4月6日

摘要: 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 阅读(332) 评论(0) 推荐(0) 编辑
摘要: 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 阅读(256) 评论(0) 推荐(0) 编辑
摘要: 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) 编辑
摘要: 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) 编辑
上一页 1 ··· 7 8 9 10 11

导航