动态规划之三:最长上升子序列与最长公共子序列问题

一.最长上升子序列1.定义LIS(i):表示以第i个数字为结尾的最长上升子序列的长度LIS(i):表示在[0...i]的范围内,选择数字nums[i]可以获得的最长上升子序列的长度LIS(i) = max(1 + LIS(j)) (i > j)2.例题300. Longest...

2018-06-14 08:18:24

阅读数:28

评论数:0

动态规划之二:0/1背包问题

一、0/1背包问题定义有一个背包,它的容量为C(Capacity)。现在有n种不同的物品,编号为0...n-1,其中每一件物品的重量为w(i),价值为v(i)。问可以向这个背包中盛放哪些物品,使得在不超过背包容量的基础上,物品的总价值最大。F(n, C):考虑将n个物品放进容量为C的背包,使得价值...

2018-06-09 17:39:27

阅读数:13

评论数:0

动态规划之一:基本思想

一.基本思想一般来说,只要问题可以划分为规模更小的字问题,并且原问题的最优解中包含了子问题的最优解,则可以考虑用动态规划解决。动态规划的实质是分治思想和解决冗余。因此,动态规划是一种将问题实例分解为更小的/相似的子问题,并存储子问题的解,使得每个子问题只求解一次,最终获得原问题的答案,以解决最优化...

2018-06-03 23:09:17

阅读数:16

评论数:0

[leetcode]贪心算法

455. Assign CookiesAssume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie. ...

2018-06-01 22:49:30

阅读数:14

评论数:0

62. Unique Paths

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 p...

2018-05-17 22:13:42

阅读数:17

评论数:0

91. Decode Ways

A message containing letters from A-Z is being encoded to numbers using the following mapping:'A' -> 1 'B' -> 2 ... 'Z' -&a...

2018-05-16 22:26:43

阅读数:14

评论数:0

279. Perfect Squares

Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ...) which sum to n.Example 1:Input: n = 12 Ou...

2018-05-15 22:33:10

阅读数:13

评论数:0

343. Integer Break

Given a positive integer n, break it into the sum of at least two positive integers and maximize the product of those integers. Return the maximum pr...

2018-05-15 22:16:29

阅读数:9

评论数:0

120. Triangle

Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the fo...

2018-05-15 21:41:11

阅读数:15

评论数:0

70. Climbing Stairs

You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you cl...

2018-04-23 22:12:30

阅读数:10

评论数:0

101. Symmetric Tree

Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree [1,2,2,3,4,4,3] is symmet...

2018-03-28 22:34:47

阅读数:27

评论数:0

100. Same Tree

Given two binary trees, write a function to check if they are the same or not.Two binary trees are considered the same if they are structurally ident...

2018-03-28 22:22:30

阅读数:20

评论数:0

226. Invert Binary Tree

Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9to 4 / \ 7 2 / \ / \ 9 6 3 1Trivia:This problem was inspir...

2018-03-28 22:13:31

阅读数:20

评论数:0

111. Minimum Depth of Binary Tree

Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest l...

2018-03-28 21:55:09

阅读数:24

评论数:0

104. Maximum Depth of Binary Tree

Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest l...

2018-03-28 21:48:54

阅读数:17

评论数:0

107. Binary Tree Level Order Traversal II

Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For ...

2018-03-26 22:00:36

阅读数:18

评论数:0

102. Binary Tree Level Order Traversal

Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree [3...

2018-03-26 21:27:50

阅读数:10

评论数:0

145. Binary Tree Postorder Traversal

Given a binary tree, return the postorder traversal of its nodes' values.For example:Given binary tree [1,null,2,3], 1 \ 2 / 3  ret...

2018-03-25 16:08:30

阅读数:12

评论数:0

94. Binary Tree Inorder Traversal

Given a binary tree, return the inorder traversal of its nodes' values.For example:Given binary tree [1,null,2,3], 1 \ 2 / 3 return...

2018-03-25 16:03:52

阅读数:16

评论数:0

144. Binary Tree Preorder Traversal

Given a binary tree, return the preorder traversal of its nodes' values.For example:Given binary tree [1,null,2,3], 1 \ 2 / 3 retur...

2018-03-25 15:59:35

阅读数:14

评论数:0

提示
确定要删除当前文章?
取消 删除
关闭
关闭