2016年9月11日

119. Pascal's Triangle II

摘要: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3,3,1]. 分析 二项式展开式的系数 不加(long long)提交会出错。 阅读全文

posted @ 2016-09-11 22:47 三颗心 阅读(142) 评论(0) 推荐(0)

118. Pascal's Triangle

摘要: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Return 阅读全文

posted @ 2016-09-11 22:41 三颗心 阅读(454) 评论(0) 推荐(0)

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 a 阅读全文

posted @ 2016-09-11 22:18 三颗心 阅读(261) 评论(0) 推荐(0)

80. Remove Duplicates from Sorted Array II

摘要: Follow up for "Remove Duplicates":What if duplicates are allowed at most twice? For example,Given sorted array nums = [1,1,1,2,2,3], Your function sho 阅读全文

posted @ 2016-09-11 16:10 三颗心 阅读(292) 评论(0) 推荐(0)

26. Remove Duplicates from Sorted Array

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

posted @ 2016-09-11 13:05 三颗心 阅读(264) 评论(0) 推荐(0)

2016年9月7日

27 Remove Element

摘要: Given an array and a value, remove all instances of that value in place and return the new length. Do not allocate extra space for another array, you 阅读全文

posted @ 2016-09-07 20:30 三颗心 阅读(144) 评论(0) 推荐(0)

2016年7月5日

从尾到头打印链表

摘要: 题目:输入一个链表的头结点,从尾到头反过来打印出每个结点的值。 思路1:使用栈 思路2:递归 阅读全文

posted @ 2016-07-05 19:57 三颗心 阅读(694) 评论(0) 推荐(0)

合并有序数组

摘要: 有两个排序数组A1和A2,内存在A1的末尾有足够多的空余空间容纳A2,实现一个函数,把A2插入到A1,并且是有序的。 分析:从尾到头比较A1和A2的数字,并把较大的数字复制到合适的位置。 阅读全文

posted @ 2016-07-05 18:46 三颗心 阅读(774) 评论(0) 推荐(0)

替换空格

摘要: 题目:请实现一个函数,把字符串中的每个空格替换成“%20”。例如输入“We are happy.”,则输出“We%20are%20happy.”。 思路:我们可以先遍历一次字符串,这样就能统计出字符串中空格的总数,并可以由此计算出替换之后的字符串的总长度。每替换一个空格,长度增加2,因此替换以后字符 阅读全文

posted @ 2016-07-05 17:18 三颗心 阅读(340) 评论(0) 推荐(0)

二维数组中的查找

摘要: 题目:在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。 思路:这题和堆排序有类似,查找过程中从右上方的数字开始,如果该数字比查找的数字小,那么该数字所在行可以删除,不用继续考虑;如果 阅读全文

posted @ 2016-07-05 15:30 三颗心 阅读(782) 评论(0) 推荐(0)

导航