Skip to content

Commit

Permalink
新增算法模块
Browse files Browse the repository at this point in the history
  • Loading branch information
lichong-a committed Sep 5, 2022
1 parent 49469b2 commit cd2eb2b
Show file tree
Hide file tree
Showing 18 changed files with 145 additions and 43 deletions.
20 changes: 20 additions & 0 deletions algorithm/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>fun-code</artifactId>
<groupId>work.lichong</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>

<name>algorithm</name>
<artifactId>algorithm</artifactId>
<description>算法题库</description>
<packaging>jar</packaging>

<build>
<finalName>algorithm</finalName>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright 2022 李冲. All rights reserved.
*
*/

package work.lichong.funcode.algorithm;

/**
* <div><a href="https://leetcode.cn/problems/lru-cache/">146. LRU 缓存</a></div>
* <div class="notranslate"><div class="title__3Vvk">请你设计并实现一个满足&nbsp; <a href="https://baike.baidu.com/item/LRU">LRU (最近最少使用) 缓存</a> 约束的数据结构。</div>
*
* <div class="title__3Vvk">实现 <code>LRUCache</code> 类:</div>
*
* <div class="original__bRMd">
* <div>
* <ul>
* <li><code>LRUCache(int capacity)</code> 以 <strong>正整数</strong> 作为容量&nbsp;<code>capacity</code> 初始化 LRU 缓存</li>
* <li><code>int get(int key)</code> 如果关键字 <code>key</code> 存在于缓存中,则返回关键字的值,否则返回 <code>-1</code> 。</li>
* <li><code>void put(int key, int value)</code>&nbsp;如果关键字&nbsp;<code>key</code> 已经存在,则变更其数据值&nbsp;<code>value</code> ;如果不存在,则向缓存中插入该组&nbsp;<code>key-value</code> 。如果插入操作导致关键字数量超过&nbsp;<code>capacity</code> ,则应该 <strong>逐出</strong> 最久未使用的关键字。</li>
* </ul>
*
* <p>函数 <code>get</code> 和 <code>put</code> 必须以 <code>O(1)</code> 的平均时间复杂度运行。</p>
* </div>
* </div>
*
* <p><strong>示例:</strong></p>
*
* <pre><strong>输入</strong>
* ["LRUCache", "put", "put", "get", "put", "get", "put", "get", "get", "get"]
* [[2], [1, 1], [2, 2], [1], [3, 3], [2], [4, 4], [1], [3], [4]]
* <strong>输出</strong>
* [null, null, null, 1, null, -1, null, -1, 3, 4]
*
* <strong>解释</strong>
* LRUCache lRUCache = new LRUCache(2);
* lRUCache.put(1, 1); // 缓存是 {1=1}
* lRUCache.put(2, 2); // 缓存是 {1=1, 2=2}
* lRUCache.get(1); // 返回 1
* lRUCache.put(3, 3); // 该操作会使得关键字 2 作废,缓存是 {1=1, 3=3}
* lRUCache.get(2); // 返回 -1 (未找到)
* lRUCache.put(4, 4); // 该操作会使得关键字 1 作废,缓存是 {4=4, 3=3}
* lRUCache.get(1); // 返回 -1 (未找到)
* lRUCache.get(3); // 返回 3
* lRUCache.get(4); // 返回 4
* </pre>
* <p><strong>提示:</strong></p>
* <ul>
* <li><code>1 &lt;= capacity &lt;= 3000</code></li>
* <li><code>0 &lt;= key &lt;= 10000</code></li>
* <li><code>0 &lt;= value &lt;= 10<sup>5</sup></code></li>
* <li>最多调用 <code>2 * 10<sup>5</sup></code> 次 <code>get</code> 和 <code>put</code></li>
* </ul>
* </div>
*
* @author 李冲
* @see <a href="https://lichong.work">李冲博客</a>
* @since 0.0.1
*/
public class LRUCache {

public LRUCache(int capacity) {

}

public int get(int key) {

return key;
}

public void put(int key, int value) {

}
}
11 changes: 8 additions & 3 deletions fun-code-dist/pom.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>fun-code</artifactId>
<groupId>work.lichong</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<name>fun-code-dist</name>
<artifactId>fun-code-dist</artifactId>
<description>打包模块</description>
<packaging>pom</packaging>

<profiles>
Expand Down Expand Up @@ -76,7 +80,8 @@
</goals>
<configuration>
<target>
<copy file="${project.build.directory}/fun-code-bin.tar.gz" tofile="${project.basedir}/../dist/fun-code-bin.tar.gz" overwrite="true" />
<copy file="${project.build.directory}/fun-code-bin.tar.gz"
tofile="${project.basedir}/../dist/fun-code-bin.tar.gz" overwrite="true"/>
</target>
</configuration>
</execution>
Expand Down
12 changes: 4 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>work.lichong</groupId>
<artifactId>fun-code</artifactId>
<version>0.0.1-SNAPSHOT</version>

<name>fun-code</name>
<description>fun-code</description>
<description>有趣的项目:主要做一些代码的记录</description>
<packaging>pom</packaging>

<modules>
<module>webmvc-demo</module>
<module>webflux-demo</module>
<module>fun-code-dist</module>
<module>algorithm</module>
</modules>

<developers>
Expand Down Expand Up @@ -58,12 +60,6 @@
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
Expand Down
3 changes: 2 additions & 1 deletion webflux-demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

<name>webflux-demo</name>
<artifactId>webflux-demo</artifactId>
<description>webflux-demo</description>
<description>集成spring webflux的示例demo</description>
<packaging>jar</packaging>

<dependencies>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package work.lichong.webflux.demo;
package work.lichong.funcode.webflux.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package work.lichong.funcode.webflux.demo;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
class WebfluxDemoApplicationTests {

@Autowired
WebfluxDemoApplication webfluxDemoApplication;

@Test
void contextLoads() {
Assertions.assertNotNull(webfluxDemoApplication);
}

}

This file was deleted.

3 changes: 2 additions & 1 deletion webmvc-demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

<name>webmvc-demo</name>
<artifactId>webmvc-demo</artifactId>
<description>webmvc-demo</description>
<description>集成spring mvc的示例demo</description>
<packaging>jar</packaging>

<properties>
<web.dir>${project.parent.basedir}/demo-web</web.dir>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package work.lichong.webmvc.demo;
package work.lichong.funcode.webmvc.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
* Copyright (c) 2022. 李冲. All rights reserved.
*/

package work.lichong.webmvc.demo.common.bean;
package work.lichong.funcode.webmvc.demo.common.bean;

import work.lichong.webmvc.demo.common.enumeration.ResponseStatus;
import work.lichong.funcode.webmvc.demo.common.enumeration.ResponseStatus;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package work.lichong.webmvc.demo.common.bean;
package work.lichong.funcode.webmvc.demo.common.bean;

import work.lichong.webmvc.demo.common.enumeration.ResponseStatus;
import work.lichong.funcode.webmvc.demo.common.enumeration.ResponseStatus;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package work.lichong.webmvc.demo.common.enumeration;
package work.lichong.funcode.webmvc.demo.common.enumeration;

/**
* http api 状态码
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright (c) 2022. 李冲. All rights reserved.
*/

package work.lichong.webmvc.demo.config;
package work.lichong.funcode.webmvc.demo.config;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright (c) 2022. 李冲. All rights reserved.
*/

package work.lichong.webmvc.demo.config;
package work.lichong.funcode.webmvc.demo.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
* Copyright (c) 2022. 李冲. All rights reserved.
*/

package work.lichong.webmvc.demo.controller;
package work.lichong.funcode.webmvc.demo.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import work.lichong.webmvc.demo.common.bean.ApiResponse;
import work.lichong.webmvc.demo.common.enumeration.ResponseStatus;
import work.lichong.webmvc.demo.model.User;
import work.lichong.funcode.webmvc.demo.common.bean.ApiResponse;
import work.lichong.funcode.webmvc.demo.common.enumeration.ResponseStatus;
import work.lichong.funcode.webmvc.demo.model.User;

/**
* @author lichong
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
* Copyright (c) 2022. 李冲. All rights reserved.
*/

package work.lichong.webmvc.demo.controller.advice;
package work.lichong.funcode.webmvc.demo.controller.advice;

import work.lichong.webmvc.demo.common.bean.ApiResponse;
import work.lichong.webmvc.demo.common.enumeration.ResponseStatus;
import work.lichong.funcode.webmvc.demo.common.bean.ApiResponse;
import work.lichong.funcode.webmvc.demo.common.enumeration.ResponseStatus;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright (c) 2022. 李冲. All rights reserved.
*/

package work.lichong.webmvc.demo.model;
package work.lichong.funcode.webmvc.demo.model;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
Expand Down

0 comments on commit cd2eb2b

Please sign in to comment.