摘要:
动态规划之背包问题 例题 现有4样物品n = ['a', 'b', 'c', 'd'],重量分别为w = [2, 4, 5, 3],价值分别为v = [5, 4, 6, 2]。背包最大承重c = 9。 现求背包可以装下的最大价值。 解答 对于动态规划的三个关键要素: 1. 边界。F(i, 0) = 阅读全文
摘要:
动态规划与递归 最大值问题 给定一组序列 [1, 2, 4, 1, 7, 8, 3],求不相邻元素求和的最大值 递归 递归的思想是从后到前进行回溯 将序列记为arr,对于最后一个元素3,记为arr[6],有两种方案。 1. 选择该值,则最优解为OPT[6] = OPT[4] + arr[6] 2. 阅读全文
摘要:
40.数组中只出现一次的数字 一个整型数组里除了两个数字之外,其他的数字都出现了两次。写出这两个只出现了一次的数字。时间复杂度为O(n),空间复杂度为O(1)。 Leetcode 540.Single Element in a Sorted Array You are given a sorted 阅读全文
摘要:
[剑指Offer]41 和为S的两个数字 VS 和为S的连续正数序列 Leetcode T1 Two Sum Given an array of integers, return indices of the two numbers such that they add up to a specif 阅读全文
摘要:
108. Convert Sorted Array to Binary Search Given an array where elements are sorted in ascending order, convert it to a height balanced BST. For this 阅读全文
摘要:
114 Flatten Binary Tree to Linked List Given a binary tree, flatten it to a linked list in place. 将二叉树展开成链表 [ ] (D:\dataStructure\Leetcode\114.png) 思路 阅读全文