LeetCode算法笔记–Day45
题目1:
64. Minimum Path Sum
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.
Note: You can only move either down or right at any point in time.
example
input: [
[1,3,1],
[1,5,1],
[4,2,1]
]output: 7
Explanation: Because the path 1→3→1→1→1 minimizes the sum.
快速排序
My Answer:
1 | /** |
题目2:
75. Sort Colors
Given an array with n objects colored red, white or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the order red, white and blue.
Here, we will use the integers 0, 1, and 2 to represent the color red, white, and blue respectively.
Note: You are not suppose to use the library’s sort function for this problem.
example
input: [2,0,2,1,1,0]
output: [0,0,1,1,2,2]
动态规划
时间复杂度:由于对长度 NN的数组进行了一次遍历,时间复杂度为O(N)
空间复杂度:由于只使用了常数空间,空间复杂度为O(1)
My Answer:
1 | /** |