数据结构与算法
炼丹大法
这个作者很懒,什么都没留下…
展开
-
栈
栈 用数组实现一个顺序栈 用链表实现一个链式栈 编程模拟实现一个浏览器的前进、后退功能 Valid Parentheses(有效的括号) 英文版:文版:https://leetcode.com/problems/valid-parentheses/ 中文版 中文版:文版:https://leetcode-cn.com/problems/valid-parentheses/ Lon Longest ...原创 2019-03-02 17:02:24 · 77 阅读 · 0 评论 -
递归+回溯+分治+动态规划
1.递归 思考以下几个问题: 边界条件 递归前进段 (子问题的递推公式) 递归返回段 (最小子问题,即在程序的边界) 爬楼梯 假设你正在爬楼梯。需要 n 阶你才能到达楼顶。 每次你可以爬 1 或 2 个台阶。你有多少种不同的方法可以爬到楼顶呢?· from functools import lru_cache class Solution: @lru_cache(10**8) ...原创 2019-03-16 22:53:59 · 599 阅读 · 0 评论 -
二叉树
实现一个二叉查找树,并且支持插入、删除、查找操作 实现查找二叉查找树中某个节点的后继、前驱节点 实现二叉树前、中、后序以及按层遍历 完成leetcode上的验证二叉搜索树(98)及二叉树 层次遍历(102,107) ...原创 2019-03-11 21:55:23 · 108 阅读 · 0 评论 -
散列表
实现一个基于链表法解决冲突问题的散列表 public class ChainingHashSet { public static class HashSet<K,V>{ private int num; private int capacity; private SearchNode<K,V>[] st; public H...原创 2019-03-07 23:56:18 · 158 阅读 · 0 评论 -
字符串
实现一个字符集,只包含 a~z 这 26 个英文字母的 Trie 树 import java.util.LinkedList; class Node{ char content; boolean isEnd; int count; LinkedList<Node> childList; public Node(char c) { childList=new Linke...原创 2019-03-07 23:55:18 · 171 阅读 · 0 评论 -
二分查找
实现一个有序数组的二分查找算法 public class BinarySearch { public static int binarysearch(int[] arr, int key, int low, int high) { if(low <= high) { int mid=low + (high - low)/2; if(key == arr[mid]) { ...原创 2019-03-05 21:19:13 · 91 阅读 · 0 评论 -
递归
编程实现斐波那契数列求值 f(n)=f(n-1)+f(n-2) 编程实现求阶乘 n! 编程实现一组数据集合的全排列 Climbing Stairs(爬楼梯) 英文版:文版:https://leetcode.com/problems/clim ...原创 2019-03-02 18:26:47 · 86 阅读 · 0 评论 -
排序
归并排序 public class Merge{ private static int[] aux; public static void sort(int[] a){ aux = new int[a.length]; sort(a, 0, a.lemgth-1); } private static void sort(int[] a, int lo, int hi){ i...原创 2019-03-05 20:53:43 · 76 阅读 · 0 评论 -
队列
队列 用数组实现一个顺序队列 用链表实现一个链式队列 public class Queue&lt;Item&gt;{ private Node first; private Node last; private int N; private class Node{ Item item; Node next; } public boolean isEmpty(){ retur...原创 2019-03-02 18:11:11 · 86 阅读 · 0 评论 -
图的深度优先搜索和广度优先搜索
1、深度优先搜索介绍 图的深度优先搜索(Depth First Search),和树的先序遍历比较类似。 它的思想:假设初始状态是图中所有顶点均未被访问,则从某个顶点v出发,首先访问该顶点,然后依次从它的各个未被访问的邻接点出发深度优先搜索遍历图,直至图中所有和v有路径相通的顶点都被访问到。 若此时尚有其他顶点未被访问到,则另选一个未被访问的顶点作起始点,重复上述过程,直至图中所有顶点都被访问到为...原创 2019-03-13 20:11:55 · 122 阅读 · 0 评论