08 2014 档案

Insertion Sort List
摘要:Sort a linked list using insertion sort.分析:插入排序的过程是从第二个元素开始,将该元素插入到前面已拍好序的序列的正确位置。如果数据结构是单链表,则主要考察单链表的结点移动操作。将一个结点插入到另一个结点的前面,需要这两个结点的previous结点。特别要注意... 阅读全文

posted @ 2014-08-20 16:19 Ryan-Xing 阅读(149) 评论(0) 推荐(0)

Next Permutation
摘要:Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possibl... 阅读全文

posted @ 2014-08-19 00:14 Ryan-Xing 阅读(143) 评论(0) 推荐(0)

Palindrome Partitioning
摘要:Given a strings, partitionssuch that every substring of the partition is a palindrome.Return all possible palindrome partitioning ofs.For example, giv... 阅读全文

posted @ 2014-08-18 13:50 Ryan-Xing 阅读(126) 评论(0) 推荐(0)

Add Binary
摘要:Given two binary strings, return their sum (also a binary string).For example,a ="11"b ="1"Return"100".分析:该题需要注意的地方:1)两个string的长度可能不同 2)近位借鉴leetcode-c... 阅读全文

posted @ 2014-08-18 13:20 Ryan-Xing 阅读(167) 评论(0) 推荐(0)

Validate Binary Search Tree
摘要:Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only n... 阅读全文

posted @ 2014-08-18 12:03 Ryan-Xing 阅读(128) 评论(0) 推荐(0)

Leetcode: Letter Combinations of a Phone Number
摘要:Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephon... 阅读全文

posted @ 2014-08-17 15:44 Ryan-Xing 阅读(156) 评论(0) 推荐(0)

Construct Binary Tree from Inorder and Postorder Traversal
摘要:Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree. 1 class Solut... 阅读全文

posted @ 2014-08-17 00:12 Ryan-Xing 阅读(138) 评论(0) 推荐(0)

Construct Binary Tree from Preorder and Inorder Traversal
摘要:Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.分析:通过一个二叉树的先序遍历... 阅读全文

posted @ 2014-08-16 23:28 Ryan-Xing 阅读(165) 评论(0) 推荐(0)

Combination Sum
摘要:Given a set of candidate numbers (C) and a target number (T), find all unique combinations inCwhere the candidate numbers sums toT.Thesamerepeated num... 阅读全文

posted @ 2014-08-16 16:33 Ryan-Xing 阅读(117) 评论(0) 推荐(0)

Partition List
摘要:Given a linked list and a valuex, partition it such that all nodes less thanxcome before nodes greater than or equal tox.You should preserve the origi... 阅读全文

posted @ 2014-08-16 15:58 Ryan-Xing 阅读(200) 评论(0) 推荐(0)

Binary Tree Zigzag Level Order Traversal
摘要:Given a binary tree, return thezigzag level ordertraversal of its nodes' values. (ie, from left to right, then right to left for the next level and al... 阅读全文

posted @ 2014-08-16 00:15 Ryan-Xing 阅读(118) 评论(0) 推荐(0)

Triangle
摘要:Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the fol... 阅读全文

posted @ 2014-08-15 23:26 Ryan-Xing 阅读(229) 评论(0) 推荐(0)

Subsets II
摘要:Given a collection of integers that might contain duplicates,S, return all possible subsets.Note:Elements in a subset must be in non-descending order.... 阅读全文

posted @ 2014-08-15 20:39 Ryan-Xing 阅读(370) 评论(0) 推荐(0)

3Sum Closest
摘要:Given an arraySofnintegers, find three integers inSsuch that the sum is closest to a given number, target. Return the sum of the three integers. You m... 阅读全文

posted @ 2014-08-15 19:26 Ryan-Xing 阅读(140) 评论(0) 推荐(0)

abs(INT_MAX-(-1))
摘要:写一个程序,结果总是不对,check逻辑好几遍也没发现错误,无奈之下debug。发现一个有趣的现象abs(INT_MAX-(-1))返回值是-2147483648。于是看了下abs函数的代码实现。1 int __cdecl abs (2 int number3 )4 ... 阅读全文

posted @ 2014-08-15 17:03 Ryan-Xing 阅读(586) 评论(0) 推荐(0)

Unique Binary Search Tree II
摘要:Givenn, generate all structurally uniqueBST's(binary search trees) that store values 1...n.For example,Givenn= 3, your program should return all 5 uni... 阅读全文

posted @ 2014-08-14 17:00 Ryan-Xing 阅读(195) 评论(0) 推荐(0)

Convert Sorted List to Binary Search Tree
摘要:Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.分析:将一个按升序排列的单链表转换成一个平衡二叉查找树,难点在于如何确定单链表的中... 阅读全文

posted @ 2014-08-14 15:27 Ryan-Xing 阅读(149) 评论(0) 推荐(0)

Jump Game
摘要:Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximu... 阅读全文

posted @ 2014-08-13 13:41 Ryan-Xing 阅读(391) 评论(0) 推荐(0)

Path Sum II
摘要:Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.For example:Given the below binary tree andsum =... 阅读全文

posted @ 2014-08-13 13:30 Ryan-Xing 阅读(120) 评论(0) 推荐(0)

Count and Say
摘要:The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1is read off as"one 1"or11.11is read off as"tw... 阅读全文

posted @ 2014-08-13 12:54 Ryan-Xing 阅读(436) 评论(0) 推荐(0)

Search for a Range
摘要:Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the ord... 阅读全文

posted @ 2014-08-12 14:59 Ryan-Xing 阅读(181) 评论(0) 推荐(0)

Unique Paths II
摘要:Follow up for "Unique Paths":Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle and empty space i... 阅读全文

posted @ 2014-08-12 14:30 Ryan-Xing 阅读(108) 评论(0) 推荐(0)

Subsets
摘要:Given a set of distinct integers,S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not co... 阅读全文

posted @ 2014-08-12 00:44 Ryan-Xing 阅读(201) 评论(0) 推荐(0)

Valid Sudoku
摘要:这道题是个细节实现题,只要把valid sudoku满足的三个条件判断一下即可。valid sudoku需满足下列三个条件:1)每一行数字1~9有且只出现一次。2)每一列数字1~9有且只出现一次。3)对于每个3*3的sub-box(用i=3、6,j=3、6两条线划分,总共9个sub-box)数字1~... 阅读全文

posted @ 2014-08-10 21:16 Ryan-Xing 阅读(173) 评论(0) 推荐(0)

Longest Consecutive Sequence
摘要:Given an unsorted array of integers, find the length of the longest consecutive elements sequence.For example,Given[100, 4, 200, 1, 3, 2],The longest ... 阅读全文

posted @ 2014-08-10 14:31 Ryan-Xing 阅读(140) 评论(0) 推荐(0)

Valid Parentheses
摘要:Given a string containing just the characters'(',')','{','}','['and']', determine if the input string is valid.The brackets must close in the correct ... 阅读全文

posted @ 2014-08-10 13:36 Ryan-Xing 阅读(87) 评论(0) 推荐(0)

Trapping Rain Water
摘要:Givennnon-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.分析... 阅读全文

posted @ 2014-08-09 23:01 Ryan-Xing 阅读(124) 评论(0) 推荐(0)

Palindrome Number
摘要:Determine whether an integer is a palindrome. Do this without extra space.按照palindrome的定义,负数一定不是palindrome number。而且palindrome number肯定是沿着中轴(可能为一个数或者两... 阅读全文

posted @ 2014-08-09 17:55 Ryan-Xing 阅读(183) 评论(0) 推荐(0)

Sum Root to Leaf Numbers
摘要:Given a binary tree containing digits from0-9only, each root-to-leaf path could represent a number.An example is the root-to-leaf path1->2->3which rep... 阅读全文

posted @ 2014-08-07 17:25 Ryan-Xing 阅读(86) 评论(0) 推荐(0)

Remove Nth Node From End of List
摘要:这道题可以用双指针的方法解,将两个指针p,q的距离保持在n-1,然后移动q到List的最后一个元素,那么此时p指向的便是the Nth node from the end。要删除这个node,要分两种情况,一种是该node为head,另一种该node是中间node。对于第一种情况,可以简单的采用以下... 阅读全文

posted @ 2014-08-07 16:36 Ryan-Xing 阅读(117) 评论(0) 推荐(0)

Leetcode:Combinations
摘要:Question: Given two integersnandk, return all possible combinations ofknumbers out of 1 ...n.要产生全部的combinations,我们需要一种有序的方式产生combination以达到既产生全部又没有重复的... 阅读全文

posted @ 2014-08-05 13:20 Ryan-Xing 阅读(119) 评论(0) 推荐(0)

Search in Rotated Sorted Array I
摘要:要搜索的对象是一个rotated sorted array,所以从直觉上时间复杂度应该不会超过O(logn)。解决这个题目的另一个思路就是先把pivot找出来,在这里我把pivot定义为数组中最小的那个数。所以下面要解决的便是能不能在O(logn)的时间找到pivot。沿着这个思路,然后综合rota... 阅读全文

posted @ 2014-08-02 14:33 Ryan-Xing 阅读(196) 评论(0) 推荐(0)

Spiral Matrix II
摘要:这道题实质是用螺旋线的形式遍历二维数组,而且这种遍历方式有很强的规律性,从最外层开始一直到最里层,而且每层都按顺时针的方向遍历。根据这种规律性,我们可以用两层循环,在遍历的同时对二维数组对应元素重新赋值,第一层循环是层数遍历,第二层循环是每一层元素遍历(值得注意的一点是顺时针遍历)。class So... 阅读全文

posted @ 2014-08-01 16:30 Ryan-Xing 阅读(176) 评论(0) 推荐(0)

Leetcode:N-Queens II
摘要:Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.分析:跟N-Queens一样,DFS+Backtrac... 阅读全文

posted @ 2014-08-01 14:03 Ryan-Xing 阅读(223) 评论(0) 推荐(0)