摘要:
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, 阅读全文
摘要:
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 ... 阅读全文
摘要:
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 阅读全文
摘要:
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 阅读全文
摘要:
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 阅读全文
摘要:
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 阅读全文
摘要:
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 阅读全文
摘要:
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 阅读全文