- 博客(13)
- 资源 (1)
- 收藏
- 关注
原创 LintCode(M)打劫房屋2——动态规划
思路: 最后一次的状态方程为: i=nums.size()-1;//i为最后一家 a[i]=max(houseRobber(A)+nums[i], houseRobber(B)); 说明:1. houseRobber(A)+nums[i]为抢最后一家的情况, A为{nums[1]….nums[i-2]}//少了第一家和最后两家。 2. houseRobb
2016-08-30 21:32:47 1233
原创 LintCode(M)打劫房屋(动态规划)
最初代码:class Solution {public: /** * @param A: An array of non-negative integers. * return: The maximum amount of money you can rob tonight */ long long houseRobber(vector<int> A)
2016-08-30 15:04:57 687
原创 LintCode(M)最小调整代价(待续)
最初有bug的代码:class Solution {public: /** * @param A: An integer array. * @param target: An integer. */ int MinAdjustmentCost(vector<int> A, int target) { // write your code here
2016-08-29 20:57:26 725
原创 LintCode(M)背包问题2
public class Solution { /** * @param m: An integer m denotes the size of a backpack * @param A & V: Given n items with size A[i] and value V[i] * @return: The maximum value */
2016-08-27 15:10:13 469
原创 LintCode(M)背包问题
以下代码为网上找的public class Solution { /** * @param m: An integer m denotes the size of a backpack * @param A: Given n items with size A[i] * @return: The maximum size */ public i
2016-08-26 16:48:01 529
原创 LintCode(easy)不同的路径
以下代码超时:class Solution {public: /** * @param n, m: positive integer (1 <= n ,m <= 100) * @return an integer */ int uniquePaths(int m, int n) { // wirte your code here int
2016-08-26 15:55:18 418
原创 LintCode(easy)删除元素
class Solution {public: /** *@param A: A list of integers *@param elem: An integer *@return: The new length after remove */ int removeElement(vector<int> &A, int elem) {
2016-08-08 12:10:31 338
原创 LintCode(easy)删除排序数组中重复数字II
基本类似删除排序数组中重复数字Iclass Solution {public: /** * @param A: a list of integers * @return : return an integer */ int removeDuplicates(vector<int> &nums) { // write your code
2016-08-08 11:24:51 323
原创 LintCode(easy)删除排序数组中重复元素
bug1:int removeDuplicates(vector<int> &nums) { // write your code here vector<int>::iterator it; map<int, int>m1; for (it = nums.begin(); it != nums.end();++it){ if (m1[*it]>0)
2016-08-08 11:22:00 237
原创 LintCode(easy)合并排序数组II
class Solution {public: /** * @param A: sorted integer array A which has m elements, * but size of A is m+n * @param B: sorted integer array B which has n elements *
2016-08-08 10:54:11 321
原创 LintCode(easy)合并排序数组
class Solution {public: /** * @param A and B: sorted integer array A and B. * @return: A new sorted integer array */ vector<int> mergeSortedArray(vector<int> &A, vector<int> &B)
2016-08-08 09:32:14 428
原创 LintCode(easy)主元素
class Solution {public: /** * @param nums: A list of integers * @return: The majority number */ int majorityNumber(vector<int> nums) { // write your code here ma
2016-08-08 09:27:23 350
原创 LintCode(easy)两数组的交
class Solution {public: /** * @param nums1 an integer array * @param nums2 an integer array * @return an integer array */ vector<int> intersection(vector<int>& nums1, vecto
2016-08-07 21:30:31 349
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人