- 博客(9)
- 收藏
- 关注
原创 leetcode-62&63 Unique Paths I & II
一,第62题,unique paths I A robot is located at the top-left corner of a m x n grid (marked ‘Start’ in the diagram below).The robot can only move either down or right at any point in time. The robot is tr
2015-05-14 20:06:36 450
原创 leetcode-118&119 Pascal's Triangle I & II
题干: Given numRows, generate the first numRows of Pascal’s triangle.For example, given numRows = 5, Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1] ] 题目就是中国的杨辉三角。 采用递归解决,为了节
2015-05-13 10:52:24 398
原创 leetcode-66 Plus One
题目: Given a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most significant digit is at the head of the list. 题目简单,用一个int型vector数组存储
2015-05-12 16:10:58 455
原创 leetcode-26&80 Remove Duplicates from Sorted Array I&II
题干: Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this in place with
2015-05-12 11:35:38 409
原创 leetcode-27 Remove Element
题目: 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.本题简单,
2015-05-11 15:52:37 456
原创 leetcode-189 Rotate Array
题目: Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4].分析:本题比较简单,秒懂。简单点,就是将数组的倒数k个数移到前面,其他的依次后移。class So
2015-05-08 11:35:04 379
原创 leetcode-39&40&216 Combination Sum I&II&III
本题思路与KSum类似。 区别有二: 第一,允许同一个数字多次使用; 第二,答案包括的1Sum,2Sum,……,KSum的结果,而不仅仅只有KSum。代码如下:class Solution {public: /* 思路:第一,先升序排序,然后去掉其中的重复项,得到C。 第二,T/C[0] = n,即最多n个数的和,最多为NSum。 第三
2015-05-06 19:26:49 420
原创 leetcode-17 Letter Combination of a Phone Number
题目意思明了。 理解容易,实现困难。 第一想法是用for循环,但是无法确定输入字符串的位数,无法确定循环层数。 因此想到用递归。 自己写的不给力,参考了高人的代码,自己摸索着写的。 哎,路漫漫其修远兮class Solution {public://对应转化表vector<string> digitToLetter = {"0","1","abc","def","ghi","jkl"
2015-05-05 18:21:13 421
原创 leetcode-38 Count and Say
开始没看懂题目,查了一下……囧。 思路很清晰,自己写的程序经过修改精简后,如下:class Solution {public:string countAndSay( int n){ if( n <= 0)//排除不符合条件的n return "";//输出为空 string say = "1";//用于保存结果,初始化为“1” for( int i = 1; i
2015-05-04 17:00:09 384
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人