01 2021 档案
摘要:package LeetCode_769 /** * 769. Max Chunks To Make Sorted * https://leetcode.com/problems/max-chunks-to-make-sorted/ * Given an array arr that is a pe
阅读全文
摘要:备忘录(Memonto)模式又叫做快照模式(Snapshot Pattern)或Token模式,是对象的行为模式。 (学习) 备忘录对象是一个用来存储另外一个对象内部状态的快照的对象。备忘录模式的用意是在不破坏封装的条件下,将一个对象的状态捕捉(Capture)住,并外部化,存储起来,从而可以在将来
阅读全文
摘要:访问者(Visitor)模式是对象的行为模式。访问者模式的目的是封装一些施加于某种数据结构元素之上的操作。一旦这些操作需要修改的话,接受这个操作的数据则可以保持不变。 (学习) 分派的概念 变量被声明时的类型叫做变量的静态类型(Static Type),有些人又把静态类型叫做明显类型(Apparen
阅读全文
摘要:解释器(Interpreter)模式是类的行为模式。给定一个语言之后,解释器模式可以定义出其文法的一种表示,并同时提供一个解释器。客户端可以使用这个解释器来解释这个语言中的句子。(学习) 解释器模式的结构 下面就以一个示意性的系统为例,讨论解释器模式的结构。系统的结构图如下: 模式所涉及的角色如下所
阅读全文
摘要:调停者模式是对象的行为模式。调停者模式包装了一系列对象相互作用的方式,使得这些对象不必相互明显引用。从而便它们可以较松散地耦合。当这些对象中的某些对象之间的相互作用发生改变时,不会立即影响到其它的一些对象之间的相互作用。从而保证这些相互作用可以彼此独立地变化。 (学习) 为什么需要调停者 如下图所示
阅读全文
摘要:合成模式属于对象的结构模式,有时又叫做“部分-整体”模式。合成模式将对象组织到树结构中,可以用来描述整体与部分的关系。合成模式可以使客户端将单纯元素与复合元素同等看待。 (学习) 合成模式 合成模式把部分和整体的关系用树结构表示出来。合成模式使得客户端把一个个单独的成分对象和由它们复合面成的合成对象
阅读全文
摘要:策略模式(Strategy)属于对象的行为模式。其用意是针对一组算法,将每一个算法封装到具有共同接口的独立的类中,从而使得它们可以相互替换。策略模式使得算法可以在不影响到客户端的情况下发生变化。 (学习) 策略模式的结构 策略模式是对算法的包装,是把使用算法的责任和算法本身分割开来,委派给不同的对象
阅读全文
摘要:模板方法模式是类的行为模式。准备一个抽象类,将部分逻辑以具体方法以及具体构造函数的形式实现,然后声明一些抽象方法来迫使子类实现余下的逻辑。不同的子类可以以不同的方式实现这些抽象方法,从而对剩余的逻辑有不同的实现。这就是模板方法模式的用意。 (学习) 模板方法模式的结构 模板方法模式是所有模式中最为常
阅读全文
摘要:观察者模式是对象的行为模式,以叫发布-订阅(Publish/Subscribe)模式、模型-视图(Model/View)模式、源-监听器(Source/Listener)模式或从属者(Dependents)模式。 (学习) 观察者模式定义了一种一对多的依赖关系,让多个观察者对象同时监听某一个主题对象
阅读全文
摘要:迭代子模式又叫游标(Cursor)模式,是对象的行为模式。迭代子模式可以顺序地访问一个聚集中的元素而不必暴露聚集的内部表象(internal representation)。 (学习) 聚集和java聚集 多个对象聚在一起形成的总体称之为聚集(Aggregate),聚集对象是能够包容一组对象的容器对
阅读全文
摘要:门面模式(Facade)是对象的结构模式,外部与一个子系统的通信必顺通过一个统一的门面对象进行。门面模式提供一个高层次的接口,使得子系统更易于使用。 (参考) 门面模式的结构 由于门面模式的结构图过于抽象,因此把它稍稍具体点。假设子系统内有三个模块,分别是ModuleA, ModuleB, Modu
阅读全文
摘要:package LeetCode_1395 /** * 1395. Count Number of Teams * https://leetcode.com/problems/count-number-of-teams/ * There are n soldiers standing in a li
阅读全文
摘要:package LeetCode_747 /** * 747. Largest Number At Least Twice of Others * https://leetcode.com/problems/largest-number-at-least-twice-of-others/ * In
阅读全文
摘要:package LeetCode_1160 /** * 1160. Find Words That Can Be Formed by Characters * https://leetcode.com/problems/find-words-that-can-be-formed-by-charact
阅读全文
摘要:package LeetCode_1539 /** * 1539. Kth Missing Positive Number * https://leetcode.com/problems/kth-missing-positive-number/ * Given an array arr of pos
阅读全文
摘要:package LeetCode_832 /** * 832. Flipping an Image * https://leetcode.com/problems/flipping-an-image/ * Given a binary matrix A, we want to flip the im
阅读全文
摘要:package LeetCode_273 /** * 273. Integer to English Words * https://leetcode.com/problems/integer-to-english-words/ * Convert a non-negative integer nu
阅读全文
摘要:package LeetCode_697 /** * 697. Degree of an Array * https://leetcode.com/problems/degree-of-an-array/description/ * Given a non-empty array of non-ne
阅读全文
摘要:package LeetCode_85 /** * 85. Maximal Rectangle * https://leetcode.com/problems/maximal-rectangle/ * Given a rows x cols binary matrix filled with 0's
阅读全文
摘要:package LeetCode_1726 /** * 1726. Tuple with Same Product * https://leetcode.com/problems/tuple-with-same-product/ * Given an array nums of distinct p
阅读全文
摘要:package LeetCode_1725 /** * 1725. Number Of Rectangles That Can Form The Largest Square * https://leetcode.com/problems/number-of-rectangles-that-can-
阅读全文
摘要:package LeetCode_1031 /** * 1031. Maximum Sum of Two Non-Overlapping Subarrays * https://leetcode.com/problems/maximum-sum-of-two-non-overlapping-suba
阅读全文
摘要:package LeetCode_839 import java.util.* import kotlin.collections.HashSet /** * 839. Similar String Groups * https://leetcode.com/problems/similar-str
阅读全文
摘要:package LeetCode_443 /** * 443. String Compression * https://leetcode.com/problems/string-compression/ * Given an array of characters chars, compress
阅读全文
摘要:package LeetCode_439 import java.util.* /** * 439. Ternary Expression Parser * (Prime) * Given a string representing arbitrarily nested ternary expres
阅读全文
摘要:package LeetCode_775 /** * 775. Global and Local Inversions * https://leetcode.com/problems/global-and-local-inversions/ * We have some permutation A
阅读全文
摘要:package LeetCode_362 import java.util.* import kotlin.collections.HashMap /** * 362. Design Hit Counter * (Prime) * Design a hit counter which counts
阅读全文
摘要:package _interview_question /** * Good morning! Here's your coding interview problem for today. This problem was asked by Facebook. Given an array of
阅读全文
摘要:package LeetCode_1202 import java.util.* import kotlin.collections.HashMap /** * 1202. Smallest String With Swaps * https://leetcode.com/problems/smal
阅读全文
摘要:package LeetCode_1720 /** * 1720. Decode XORed Array * https://leetcode.com/problems/decode-xored-array/ * There is a hidden integer array arr that co
阅读全文
摘要:package LeetCode_1721 /** * 1721. Swapping Nodes in a Linked List * https://leetcode.com/problems/swapping-nodes-in-a-linked-list/ * You are given the
阅读全文
摘要:package LeetCode_300 /** * 300. Longest Increasing Subsequence * https://leetcode.com/problems/longest-increasing-subsequence/description/ * Given an
阅读全文
摘要:package LeetCode_495 /** * 495. Teemo Attacking * https://leetcode.com/problems/teemo-attacking/ * In LOL world, there is a hero called Teemo and his
阅读全文
摘要:package LeetCode_665 /** * 665. Non-decreasing Array * https://leetcode.com/problems/non-decreasing-array/ * Given an array nums with n integers, your
阅读全文
摘要:package LeetCode_643 /** * 643. Maximum Average Subarray I * https://leetcode.com/problems/maximum-average-subarray-i/ * Given an array consisting of
阅读全文
摘要:package LeetCode_605 /** * 605. Can Place Flowers * https://leetcode.com/problems/can-place-flowers/ * You have a long flowerbed in which some of the
阅读全文
摘要:package LeetCode_1184 /** * 1184. Distance Between Bus Stops * https://leetcode.com/problems/distance-between-bus-stops/ * A bus has n stops numbered
阅读全文
摘要:package LeetCode_1711 /** * 1711. Count Good Meals * https://leetcode.com/problems/count-good-meals/ * A good meal is a meal that contains exactly two
阅读全文
摘要:package LeetCode_1710 import java.util.* /** * 1710. Maximum Units on a Truck * https://leetcode.com/problems/maximum-units-on-a-truck/ * You are assi
阅读全文
摘要:package LeetCode_566 /** * 566. Reshape the Matrix * https://leetcode.com/problems/reshape-the-matrix/ * In MATLAB, there is a very useful function ca
阅读全文
摘要:package LeetCode_980 /** * 980. Unique Paths III * https://leetcode.com/problems/unique-paths-iii/ * * On a 2-dimensional grid, there are 4 types of s
阅读全文
摘要:package LeetCode_212 /** * 212. Word Search II * https://leetcode.com/problems/word-search-ii/ * Given an m x n board of characters and a list of stri
阅读全文