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 阅读(117) 评论(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 阅读(171) 评论(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 阅读(81) 评论(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 阅读(113) 评论(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 阅读(111) 评论(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 阅读(183) 评论(0) 推荐(0) 编辑

Spiral Matrix II

摘要: 这道题实质是用螺旋线的形式遍历二维数组,而且这种遍历方式有很强的规律性,从最外层开始一直到最里层,而且每层都按顺时针的方向遍历。根据这种规律性,我们可以用两层循环,在遍历的同时对二维数组对应元素重新赋值,第一层循环是层数遍历,第二层循环是每一层元素遍历(值得注意的一点是顺时针遍历)。class So... 阅读全文
posted @ 2014-08-01 16:30 Ryan-Xing 阅读(164) 评论(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 阅读(219) 评论(0) 推荐(0) 编辑

Leetcode:N-Queens

摘要: Then-queens puzzle is the problem of placingnqueens on ann×nchessboard such that no two queens attack each other.Given an integern, return all distinc... 阅读全文
posted @ 2014-07-31 20:46 Ryan-Xing 阅读(166) 评论(0) 推荐(0) 编辑

Relevance Between Variable Declaration and Definition in C++

摘要: A declaration makes a name known to a programm. A definition creates the assocatied entity. A variable declaration specifies the variable type and nam... 阅读全文
posted @ 2014-07-18 16:57 Ryan-Xing 阅读(222) 评论(0) 推荐(0) 编辑