Skip to content

Commit

Permalink
'更新'
Browse files Browse the repository at this point in the history
  • Loading branch information
geekxh committed Jul 26, 2021
1 parent 670c054 commit 74192b8
Show file tree
Hide file tree
Showing 52 changed files with 6,812 additions and 2 deletions.
2 changes: 1 addition & 1 deletion PART_1_算法基础/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## PART I 算法基础
## PART_1_算法基础

[下载 XMIND 完整版](https://www.cxyhub.com/all/programming/12460/)

Expand Down
2 changes: 1 addition & 1 deletion PART_2_力扣图解/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## PART II 算法图解题典
## PART_2_力扣图解

| Title | 分类 | 难度 |
|---|---|---|
Expand Down
13 changes: 13 additions & 0 deletions PART_3_大厂面试/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## PART_3_大厂面试

考虑到现在网上面经实在太杂,很多都冠以 “BAT” 之名,重复率、错误率都非常高。所以我尽可能的挑选出了我认为比较好的 50 篇面经(基本不重复),并对内容做了分类。

建议大家把这个页面收藏起来,防止后面需要的时候找不到了。

希望大家可以点个 star 支持一下~

- [系统设计-长文(非常建议读,我自己也看了)](https://github.com/donnemartin/system-design-primer/blob/master/README-zh-Hans.md)
- [后端-社招(两年): 蚂蚁 头条 PingCAP](https://github.com/aylei/interview)
- [后端-京东-JAVA](https://www.cnblogs.com/wupeixuan/p/8908524.html#%E4%B8%80%E3%80%81java)
- [后端-百度-高并发抢红包设计](https://github.com/xbox1994/Java-Interview/blob/master/MD/%E7%B3%BB%E7%BB%9F%E8%AE%BE%E8%AE%A1-%E9%AB%98%E5%B9%B6%E5%8F%91%E6%8A%A2%E7%BA%A2%E5%8C%85.md)
- [NLP(机器学习)-百度](https://www.e-learn.cn/topic/95743)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file added git
Empty file.
82 changes: 82 additions & 0 deletions hello-algorithm.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/03_01_DuplicationInArray" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/03_02_DuplicationInArrayNoEdit" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/04_FindInPartiallySortedMatrix" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/05_ReplaceSpaces" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/06_PrintListInReversedOrder" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/07_ConstructBinaryTree" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/08_NextNodeInBinaryTrees" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/09_01_QueueWithTwoStacks" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/09_02_StackWithTwoQueues" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/10_01_Fibonacci" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/10_02_JumpFloor" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/10_03_JumpFloorII" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/10_04_RectCover" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/11_MinNumberInRotatedArray" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/12_StringPathInMatrix" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/13_RobotMove" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/14_CuttingRope" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/15_NumberOf1InBinary" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/16_Power" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/17_Print1ToMaxOfNDigits" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/18_01_DeleteNodeInList" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/18_02_DeleteDuplicatedNode" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/19_RegularExpressionsMatching" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/20_NumericStrings" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/21_ReorderArray" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/22_KthNodeFromEnd" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/23_EntryNodeInListLoop" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/24_ReverseList" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/25_MergeSortedLists" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/26_SubstructureInTree" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/27_MirrorOfBinaryTree" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/28_SymmetricalBinaryTree" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/29_PrintMatrix" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/30_MinInStack" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/31_StackPushPopOrder" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/32_01_PrintTreeFromTopToBottom" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/32_02_PrintTreesInLines" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/32_03_PrintTreesInZigzag" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/33_SquenceOfBST" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/34_PathInTree" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/35_CopyComplexList" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/36_ConvertBinarySearchTree" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/37_SerializeBinaryTrees" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/38_StringPermutation" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/39_MoreThanHalfNumber" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/40_KLeastNumbers" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/41_StreamMedian" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/42_GreatestSumOfSubarrays" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/43_NumberOf1" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/44_DigitsInSequence" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/45_SortArrayForMinNumber" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/46_TranslateNumbersToStrings" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/47_MaxValueOfGifts" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/48_LongestSubstringWithoutDup" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/49_UglyNumber" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/50_01_FirstNotRepeatingChar" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/50_02_FristCharacterInStream" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/52_FirstCommonNodesInLists" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/53_01_NumberOfK" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/53_02_MissingNumber" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/53_03_IntegerIdenticalToIndex" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/54_KthNodeInBST" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/55_01_TreeDepth" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/55_02_BalancedBinaryTree" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/56_01_NumbersAppearOnce" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/56_02_NumberAppearingOnce" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/57_01_TwoNumbersWithSum" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/57_02_ContinuousSquenceWithSum" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/58_01_ReverseWordsInSentence" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/58_02_LeftRotateString" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/59_01_MaxInSlidingWindow" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/专栏/剑指offer/61_ContinousCards" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
185 changes: 185 additions & 0 deletions other/designpattern/中介者模式.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
## 中介者(Mediator)

### 介绍

中介者模式(Mediator Pattern)是用来降低多个对象和类之间的通信复杂性。这种模式提供了一个中介类,该类通常处理不同类之间的通信,并支持松耦合,使代码易于维护。中介者模式属于行为型模式。

### Intent

集中相关对象之间复杂的沟通和控制方式。

### Class Diagram

- Mediator:中介者,定义一个接口用于与各同事(Colleague)对象通信。
- Colleague:同事,相关对象

<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/30d6e95c-2e3c-4d32-bf4f-68128a70bc05.png"/> </div><br>

### Implementation

Alarm(闹钟)、CoffeePot(咖啡壶)、Calendar(日历)、Sprinkler(喷头)是一组相关的对象,在某个对象的事件产生时需要去操作其它对象,形成了下面这种依赖结构:

<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/82cfda3b-b53b-4c89-9fdb-26dd2db0cd02.jpg"/> </div><br>

使用中介者模式可以将复杂的依赖结构变成星形结构:

<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/5359cbf5-5a79-4874-9b17-f23c53c2cb80.jpg"/> </div><br>

```java
public abstract class Colleague {
public abstract void onEvent(Mediator mediator);
}
```

```java
public class Alarm extends Colleague {

@Override
public void onEvent(Mediator mediator) {
mediator.doEvent("alarm");
}

public void doAlarm() {
System.out.println("doAlarm()");
}
}
```

```java
public class CoffeePot extends Colleague {
@Override
public void onEvent(Mediator mediator) {
mediator.doEvent("coffeePot");
}

public void doCoffeePot() {
System.out.println("doCoffeePot()");
}
}
```

```java
public class Calender extends Colleague {
@Override
public void onEvent(Mediator mediator) {
mediator.doEvent("calender");
}

public void doCalender() {
System.out.println("doCalender()");
}
}
```

```java
public class Sprinkler extends Colleague {
@Override
public void onEvent(Mediator mediator) {
mediator.doEvent("sprinkler");
}

public void doSprinkler() {
System.out.println("doSprinkler()");
}
}
```

```java
public abstract class Mediator {
public abstract void doEvent(String eventType);
}
```

```java
public class ConcreteMediator extends Mediator {
private Alarm alarm;
private CoffeePot coffeePot;
private Calender calender;
private Sprinkler sprinkler;

public ConcreteMediator(Alarm alarm, CoffeePot coffeePot, Calender calender, Sprinkler sprinkler) {
this.alarm = alarm;
this.coffeePot = coffeePot;
this.calender = calender;
this.sprinkler = sprinkler;
}

@Override
public void doEvent(String eventType) {
switch (eventType) {
case "alarm":
doAlarmEvent();
break;
case "coffeePot":
doCoffeePotEvent();
break;
case "calender":
doCalenderEvent();
break;
default:
doSprinklerEvent();
}
}

public void doAlarmEvent() {
alarm.doAlarm();
coffeePot.doCoffeePot();
calender.doCalender();
sprinkler.doSprinkler();
}

public void doCoffeePotEvent() {
// ...
}

public void doCalenderEvent() {
// ...
}

public void doSprinklerEvent() {
// ...
}
}
```

```java
public class Client {
public static void main(String[] args) {
Alarm alarm = new Alarm();
CoffeePot coffeePot = new CoffeePot();
Calender calender = new Calender();
Sprinkler sprinkler = new Sprinkler();
Mediator mediator = new ConcreteMediator(alarm, coffeePot, calender, sprinkler);
// 闹钟事件到达,调用中介者就可以操作相关对象
alarm.onEvent(mediator);
}
}
```

```java
doAlarm()
doCoffeePot()
doCalender()
doSprinkler()
```

### JDK

- All scheduleXXX() methods of [java.util.Timer](http://docs.oracle.com/javase/8/docs/api/java/util/Timer.html)
- [java.util.concurrent.Executor#execute()](http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/Executor.html#execute-java.lang.Runnable-)
- submit() and invokeXXX() methods of [java.util.concurrent.ExecutorService](http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ExecutorService.html)
- scheduleXXX() methods of [java.util.concurrent.ScheduledExecutorService](http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ScheduledExecutorService.html)
- [java.lang.reflect.Method#invoke()](http://docs.oracle.com/javase/8/docs/api/java/lang/reflect/Method.html#invoke-java.lang.Object-java.lang.Object...-)

你可以通过下方扫码回复【进群】,加入我们的高端计算机学习群!以及下载超过 100 张高清思维导图!

<div align="center">
<a href="https://www.geekxh.com/code.png" style="box-shadow: rgb(210, 210, 210) 0em 0em 0.5em 0px; font-size: 17px;"><img src="https://www.geekxh.com/code.png" width="250px"></a>
</div>







102 changes: 102 additions & 0 deletions other/designpattern/享元模式.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
## 享元(Flyweight)

### 介绍

享元模式(Flyweight Pattern)主要用于减少创建对象的数量,以减少内存占用和提高性能。这种类型的设计模式属于结构型模式,它提供了减少对象数量从而改善应用所需的对象结构的方式。

享元模式尝试重用现有的同类对象,如果未找到匹配的对象,则创建新对象。我们将通过创建 5 个对象来画出 20 个分布于不同位置的圆来演示这种模式。由于只有 5 种可用的颜色,所以 color 属性被用来检查现有的 Circle 对象。

### Intent

利用共享的方式来支持大量细粒度的对象,这些对象一部分内部状态是相同的。

### Class Diagram

- Flyweight:享元对象
- IntrinsicState:内部状态,享元对象共享内部状态
- ExtrinsicState:外部状态,每个享元对象的外部状态不同

<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/5f5c22d5-9c0e-49e1-b5b0-6cc7032724d4.png"/> </div><br>

### Implementation

```java
public interface Flyweight {
void doOperation(String extrinsicState);
}
```

```java
public class ConcreteFlyweight implements Flyweight {

private String intrinsicState;

public ConcreteFlyweight(String intrinsicState) {
this.intrinsicState = intrinsicState;
}

@Override
public void doOperation(String extrinsicState) {
System.out.println("Object address: " + System.identityHashCode(this));
System.out.println("IntrinsicState: " + intrinsicState);
System.out.println("ExtrinsicState: " + extrinsicState);
}
}
```

```java
public class FlyweightFactory {

private HashMap<String, Flyweight> flyweights = new HashMap<>();

Flyweight getFlyweight(String intrinsicState) {
if (!flyweights.containsKey(intrinsicState)) {
Flyweight flyweight = new ConcreteFlyweight(intrinsicState);
flyweights.put(intrinsicState, flyweight);
}
return flyweights.get(intrinsicState);
}
}
```

```java
public class Client {

public static void main(String[] args) {
FlyweightFactory factory = new FlyweightFactory();
Flyweight flyweight1 = factory.getFlyweight("aa");
Flyweight flyweight2 = factory.getFlyweight("aa");
flyweight1.doOperation("x");
flyweight2.doOperation("y");
}
}
```

```html
Object address: 1163157884
IntrinsicState: aa
ExtrinsicState: x
Object address: 1163157884
IntrinsicState: aa
ExtrinsicState: y
```

### JDK

Java 利用缓存来加速大量小对象的访问时间。

- java.lang.Integer#valueOf(int)
- java.lang.Boolean#valueOf(boolean)
- java.lang.Byte#valueOf(byte)
- java.lang.Character#valueOf(char)

你可以通过下方扫码回复【进群】,加入我们的高端计算机学习群!以及下载超过 100 张高清思维导图!

<div align="center">
<a href="https://www.geekxh.com/code.png" style="box-shadow: rgb(210, 210, 210) 0em 0em 0.5em 0px; font-size: 17px;"><img src="https://www.geekxh.com/code.png" width="250px"></a>
</div>





Loading

0 comments on commit 74192b8

Please sign in to comment.