数据结构与算法
文章平均质量分 69
老男孩JL
这个作者很懒,什么都没留下…
展开
-
递归——Hanoi塔问题
题目: Hanoi塔问题,游戏规则:(1). 每次只能移动一只圆盘 (2). 任何时候大圆盘不能压在小圆盘之上 (3). 任何时候都不允许将圆盘放在三根立轴之外的任何地方。 分析: 递归的 base case: 当只有一个圆盘的时候,直接从圆盘所在的立轴移动到目标立轴,即完成。 递归的 recursion rule: 如图所示,要将n个圆盘从立轴A移动到立轴原创 2016-04-12 18:07:37 · 403 阅读 · 0 评论 -
递归——LeetCode203. Remove Linked List Elements
题目: Remove all elements from a linked list of integers that have value val. Example Given: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6 Return: 1 --> 2 --> 3 --> 4 --> 5 分析: 仍然依照递归的解题思路,原创 2016-04-13 13:54:14 · 187 阅读 · 0 评论 -
递归——Maze
1. 题目: Given a maze and a start point and a target point, return whether the target can be reached. 需要实现的递归函数的接口是:public static boolean solveMaze(char[][] maze, int startX, int startY, int targetX,原创 2016-04-13 14:16:28 · 385 阅读 · 0 评论 -
递归——0-1 Knapsack
最基础的0-1背包问题 题目: Given a knapsack which can hold s pounds of items, and a set of items with weight w1, w2, ... wn. Return whether we can pick specific items so that their total weight s. Example In原创 2016-04-13 15:28:27 · 451 阅读 · 0 评论 -
递归——LeetCode46. Permutation
题目: Given a collection of distinct numbers, return all possible permutations. For example, [1,2,3] have the following permutations: [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], and [3,2,原创 2016-04-13 16:10:56 · 231 阅读 · 0 评论 -
递归——LeetCode47. Permutation II
题目: Given a collection of numbers that might contain duplicates, return all possible unique permutations. For example, [1,1,2] have the following unique permutations: [1,1,2], [1,2,1], and原创 2016-04-19 14:13:26 · 217 阅读 · 0 评论