随笔分类 -  Algorithm

摘要:LRU Cache (least recently used) multi-level cache in CPU LRU: Hash Table + Double Linked List Time complexity: O(1) lookup, O(1) update/modify 其他缓存替换方 阅读全文
posted @ 2021-03-22 12:47 鹏懿如斯 阅读(55) 评论(0) 推荐(0)
摘要:Advanced Search Pruning Bidirectional Breadth First Search Heuristic search (A* Search) public class AStar { public final static int BAR = 1; // 障碍值 p 阅读全文
posted @ 2021-03-21 16:50 鹏懿如斯 阅读(45) 评论(0) 推荐(0)
摘要:Trie inner 208. Implement Trie (Prefix Tree) Trie (we pronounce "try") or prefix tree is a tree data structure used to retrieve a key in a strings dat 阅读全文
posted @ 2021-03-20 16:30 鹏懿如斯 阅读(51) 评论(0) 推荐(0)
摘要:new climb stairs step: 1 2 3, two adjacent steps cannot be the same. 120. Triangle Given a triangle array, return the minimum path sum from top to bot 阅读全文
posted @ 2021-03-19 20:19 鹏懿如斯 阅读(46) 评论(0) 推荐(0)
摘要:Binary Search premise : 1. monotonicity 2. exist upper and lower bound 3. index accessible left, right = 0, len(array) - 1 while left <= right: mid = 阅读全文
posted @ 2021-03-18 16:20 鹏懿如斯 阅读(54) 评论(0) 推荐(0)
摘要:Greedy best in present The difference between Greedy and Dynamic Programming is that it makes choices on the solutions of each sub-problem and can't r 阅读全文
posted @ 2021-03-17 14:17 鹏懿如斯 阅读(70) 评论(0) 推荐(0)
摘要:Division find sub-problems, split and merge def divide_conquer(problem, param1, param2, ...): # recursion terminator if problem is None: print_result 阅读全文
posted @ 2021-03-16 14:59 鹏懿如斯 阅读(57) 评论(0) 推荐(0)
摘要:Recursion layer by layer private xxxx recursion(level, param1, param2, ...) { // recursion terminator if (level > MAX_LEVEL) { process_result; return 阅读全文
posted @ 2021-03-15 17:47 鹏懿如斯 阅读(68) 评论(0) 推荐(0)
摘要:List: one next Tree: multi next, no cycle Graph: has cycle Binary Search Tree left children < root < right children (children! not child!) Time Comple 阅读全文
posted @ 2021-03-14 19:50 鹏懿如斯 阅读(60) 评论(0) 推荐(0)
摘要:20. Valid Parentheses Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. An inpu 阅读全文
posted @ 2021-03-13 16:49 鹏懿如斯 阅读(52) 评论(0) 推荐(0)
摘要:Stack extends class Vector Stack<T> stack = new Stack<>(); API: empty() peek() pop() push(E item) search(Object o) Recommended in practice: Deque<T> s 阅读全文
posted @ 2021-03-12 15:06 鹏懿如斯 阅读(61) 评论(0) 推荐(0)
摘要:11. Container With Most Water Given n non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i, ai). n vertical lines ar 阅读全文
posted @ 2021-03-11 16:32 鹏懿如斯 阅读(43) 评论(0) 推荐(0)
摘要:Master Theorem ArrayList When insert or delete an element, ArrayList will create a new Array and execute a System.arraycopy. Doing those constantly wi 阅读全文
posted @ 2021-03-10 19:51 鹏懿如斯 阅读(53) 评论(0) 推荐(0)
摘要:基础部分 785. 判断二分图 中等 给定一个无向图graph,当这个图为二分图时返回true。 如果我们能将一个图的节点集合分割成两个独立的子集A和B,并使图中的每一条边的两个节点一个来自A集合,一个来自B集合,我们就将这个图称为二分图。 graph将会以邻接表方式给出,graph[i]表示图中与 阅读全文
posted @ 2020-08-04 12:43 鹏懿如斯 阅读(471) 评论(0) 推荐(0)
摘要:基础部分 基本原理 0s 表示一串 0,1s 表示一串 1。 x ^ 0s = x x & 0s = 0 x | 0s = x x ^ 1s = ~x x & 1s = x x | 1s = 1s x ^ x = 0 x & x = x x | x = x 利用 x ^ 1s = ~x 的特点,可以 阅读全文
posted @ 2020-08-04 12:09 鹏懿如斯 阅读(459) 评论(0) 推荐(0)
摘要:基础部分 283. 移动零 简单 给定一个数组 nums,编写一个函数将所有 0 移动到数组的末尾,同时保持非零元素的相对顺序。 示例: 输入: [0,1,0,3,12] 输出: [1,3,12,0,0] 说明: 必须在原数组上操作,不能拷贝额外的数组。 尽量减少操作次数。 class Soluti 阅读全文
posted @ 2020-08-03 17:15 鹏懿如斯 阅读(457) 评论(0) 推荐(0)
摘要:基础部分 242. 有效的字母异位词 简单 给定两个字符串 s 和 t ,编写一个函数来判断 t 是否是 s 的字母异位词。 示例 1: 输入: s = "anagram", t = "nagaram" 输出: true 示例 2: 输入: s = "rat", t = "car" 输出: fals 阅读全文
posted @ 2020-08-03 12:19 鹏懿如斯 阅读(472) 评论(0) 推荐(0)
摘要:基础部分 1. 两数之和 简单 给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标。 你可以假设每种输入只会对应一个答案。但是,数组中同一个元素不能使用两遍。 示例: 给定 nums = [2, 7, 11, 15], targ 阅读全文
posted @ 2020-08-03 10:14 鹏懿如斯 阅读(444) 评论(0) 推荐(0)
摘要:基础部分 232. 用栈实现队列 简单 使用栈实现队列的下列操作: push(x) -- 将一个元素放入队列的尾部。 pop() -- 从队列首部移除元素。 peek() -- 返回队列首部的元素。 empty() -- 返回队列是否为空。 示例: MyQueue queue = new MyQue 阅读全文
posted @ 2020-08-02 20:37 鹏懿如斯 阅读(445) 评论(0) 推荐(0)
摘要:基础部分 递归 104. 二叉树的最大深度 简单 给定一个二叉树,找出其最大深度。 二叉树的深度为根节点到最远叶子节点的最长路径上的节点数。 说明: 叶子节点是指没有子节点的节点。 示例: 给定二叉树 [3,9,20,null,null,15,7], 3 / \ 9 20 / \ 15 7 返回它的 阅读全文
posted @ 2020-08-02 17:23 鹏懿如斯 阅读(437) 评论(0) 推荐(0)