关闭

167. Two Sum II - Input array is sorted

265人阅读 评论(0) 收藏 举报
分类:
class Solution {
public:
    int minPathSum(vector<vector<int>>& grid) {
        vector<vector<int>> dp(grid.size(),vector<int>(grid[0].size(),0));
        dp[0][0]=grid[0][0];
        for(int i=1;i<grid.size();i++)
        {
            dp[i][0]=dp[i-1][0]+grid[i][0];
        }
        for(int j=1;j<grid[0].size();j++)
        {
            dp[0][j]=dp[0][j-1]+grid[0][j];
        }
        for(int i=1;i<grid.size();i++)
            for(int j=1;j<grid[0].size();j++)
            {
                dp[i][j]=min(dp[i-1][j],dp[i][j-1])+grid[i][j];
            }
        return dp[grid.size()-1][grid[0].size()-1];
    }
};
0
0
查看评论

167. Two Sum II - Input array is sorted [medium] (Python)

题目链接https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/题目原文 Given an array of integers that is already sorted in ascending order, find t...
  • coder_orz
  • coder_orz
  • 2016-08-31 19:33
  • 2261

leetcode 167: Two Sum II - Input array is sorted

Two Sum II - Input array is sorted Total Accepted: 441 Total Submissions: 1017 Given an array of integers that is already sorted in ascending ...
  • xudli
  • xudli
  • 2014-12-31 08:27
  • 8303

LeetCode-Easy部分中标签为 Binary Search 167. Two Sum II - Input array is sorted

在升序数组中,求两个数的和等于目标值时所在的索引,分别给出最精简的Hash算法和两个指针法
  • daigualu
  • daigualu
  • 2017-04-08 22:20
  • 937

167. Two Sum II - Input array is sorted。

Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.The function ...
  • Leafage_M
  • Leafage_M
  • 2018-01-06 20:45
  • 163

Leetcode-167. Two Sum II - Input array is sorted c语言

1、题目:点击打开链接 2、下面代码是暴力破解,超时无法通过: /** * Return an array of size *returnSize. * Note: The returned array must be malloced, assume caller calls free...
  • tzh476
  • tzh476
  • 2016-09-01 20:42
  • 573

Two Sum II - Input array is sorted问题及解法

问题描述: Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number...
  • u011809767
  • u011809767
  • 2017-03-25 10:24
  • 176

LeetCode167.Two Sum II - Input array is sorted题解

1. 题目描述Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number. Th...
  • lby0910
  • lby0910
  • 2017-03-08 13:07
  • 217

LeetCode Two Sum II - Input array is sorted(Two pointer问题)

Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number. The ...
  • wuli2496
  • wuli2496
  • 2016-08-19 13:09
  • 280

【leetcode】Two Sum II - Input array is sorted(输入有序的数组,求两个数的和)

题目: given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number. T...
  • lizhidefengzi
  • lizhidefengzi
  • 2017-04-21 10:49
  • 292

167. Two Sum II - Input array is sorted**

Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number. The functio...
  • alwaystry
  • alwaystry
  • 2016-08-29 21:32
  • 161
    个人资料
    • 访问:109812次
    • 积分:4841
    • 等级:
    • 排名:第7029名
    • 原创:374篇
    • 转载:7篇
    • 译文:0篇
    • 评论:6条
    最新评论