2013年12月7日
摘要: Next Permutation2013.12.7 05:14Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest possible order (ie, sorted in ascending order).The replacement must be in-place, 阅读全文
posted @ 2013-12-07 05:34 zhuli19901106 阅读(293) 评论(0) 推荐(0) 编辑
摘要: Divide Two Integers2013.12.7 04:52Divide two integers without using multiplication, division and mod operator.Solution: Another bit-manipulation problem, integer division. Normally if we calculate x / y (x, y > 0), we'll subtract y from x until y 0 ? dividend : -(long long int)dividend;23 ... 阅读全文
posted @ 2013-12-07 05:00 zhuli19901106 阅读(348) 评论(0) 推荐(0) 编辑
摘要: Remove Element2013.12.7 04:33Given 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.Solution1: My first solution is scan the array from both ends, if a target v 阅读全文
posted @ 2013-12-07 04:33 zhuli19901106 阅读(275) 评论(0) 推荐(0) 编辑
摘要: Remove Duplicates from Sorted Array2013.12.7 03:29Given 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 阅读全文
posted @ 2013-12-07 03:42 zhuli19901106 阅读(180) 评论(0) 推荐(0) 编辑
摘要: Swap Nodes in Pairs2013.12.7 01:54Given a linked list, swap every two adjacent nodes and return its head.For example,Given1->2->3->4, you should return the list as2->1->4->3.Your algorithm should use only constant space. You maynotmodify the values in the list, only nodes itself ca 阅读全文
posted @ 2013-12-07 02:04 zhuli19901106 阅读(212) 评论(0) 推荐(0) 编辑
摘要: Merge k Sorted Lists2013.12.7 01:32Mergeksorted linked lists and return it as one sorted list. Analyze and describe its complexity.Solution: You must've done the job of merging two sorted linked lists quite often, this time it's k lists. The simple way is to find the smallest of all k head n 阅读全文
posted @ 2013-12-07 01:49 zhuli19901106 阅读(248) 评论(0) 推荐(0) 编辑
摘要: Generate Parentheses2013.12.7 00:49Givennpairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, givenn= 3, a solution set is:"((()))", "(()())", "(())()", "()(())", "()()()"Solution: If you're 阅读全文
posted @ 2013-12-07 01:06 zhuli19901106 阅读(1040) 评论(0) 推荐(0) 编辑
摘要: Valid Parentheses2013.12.7 00:03Given a string containing just the characters'(',')','{','}','['and']', determine if the input string is valid.The brackets must close in the correct order,"()"and"()[]{}"are all valid but"(]&quo 阅读全文
posted @ 2013-12-07 00:10 zhuli19901106 阅读(266) 评论(0) 推荐(0) 编辑
2013年12月6日
摘要: Remove Nth Node From End of ListGiven a linked list, remove thenthnode from the end of list and return its head.For example,Given linked list: 1->2->3->4->5, and n = 2.After removing the second node from the end, the linked list becomes 1->2->3->5.Note:Givennwill always be valid 阅读全文
posted @ 2013-12-06 21:50 zhuli19901106 阅读(220) 评论(0) 推荐(0) 编辑
摘要: Letter Combinations of a Phone Number2013.12.6 19:52Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given below.Input:Digit string "23"Output: ["ad", "ae" 阅读全文
posted @ 2013-12-06 20:08 zhuli19901106 阅读(320) 评论(0) 推荐(0) 编辑