Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Python files
__pycache__/
7 changes: 7 additions & 0 deletions anima.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env python3
import fire

import anima

if __name__ == '__main__':
fire.Fire(anima.Anima())
10 changes: 10 additions & 0 deletions anima/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from anima.create import create_solution


class Anima:
"""
LeetCode Animation Manager
"""

def new(self, id: str, title: str):
create_solution(id, title)
12 changes: 12 additions & 0 deletions anima/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import os
from pathlib import Path


def get_project_path() -> Path:
script_path = os.path.realpath(__file__)
project_path = Path(script_path).parent.parent
return project_path


def get_md_template_path() -> Path:
return get_project_path() / 'template' / 'template.md'
22 changes: 22 additions & 0 deletions anima/create.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import shutil

from anima.base import get_project_path, get_md_template_path
from anima.model import ProblemInfo, Solution


def create_solution(problem_id: int, problem_title: str) -> None:
problem = ProblemInfo(problem_id, problem_title)
solution_dir = get_project_path() / problem.title_slug()

if solution_dir.exists():
print(f'创建失败,文件夹 {solution_dir} 已存在')
exit(1)
solution_dir.mkdir()

solution = Solution.create(problem, solution_dir)

template = get_md_template_path()
shutil.copy(template, solution.doc_path())

print(f'题解框架创建完毕,位于文件夹 {solution.path}')

47 changes: 47 additions & 0 deletions anima/model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import re
from dataclasses import dataclass
from pathlib import Path


@dataclass
class ProblemInfo:
id: int
title: str

def title_slug(self):
title_parts = re.split(r'\s+', self.title)
return f'{self.id:04d}-' + '-'.join(title_parts)


@dataclass
class Solution:
problem: ProblemInfo
path: Path

@classmethod
def create(cls, problem: ProblemInfo, path: Path):
solution = Solution(problem, path)
solution._create_dirs()
return solution

def _create_dirs(self):
self.animation_path().mkdir()
self.article_path().mkdir()
self.code_path().mkdir()
(self.animation_path() / 'Animation.m4v').touch()
(self.animation_path() / 'Animation.gif').touch()

def _path_to(self, s: str) -> Path:
return self.path / s

def animation_path(self) -> Path:
return self.path / 'Animation'

def article_path(self) -> Path:
return self.path / 'Article'

def doc_path(self) -> Path:
return self.article_path() / (self.problem.title_slug() + '.md')

def code_path(self) -> Path:
return self.path / 'Code'
18 changes: 18 additions & 0 deletions contributing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
## LeetCode Animation 管理脚本 anima 使用说明

需要使用 Python 3.6+ 版本

安装依赖:

```
pip install -r requirements.txt
```

### 创建新题解

生成题解目录框架,以及 Markdown 文件模板。

```
python anima.py new 1 'Two Sum'
```

1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fire
26 changes: 26 additions & 0 deletions template/template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# LeetCode 图解 |

> 本文首发于公众号「图解面试算法」,是 [图解 LeetCode](<https://github.com/MisterBooo/LeetCodeAnimation>) 系列文章之一。
>
> 同步博客:https://www.algomooc.com
本题解作者:

## 题目描述



## 题目解析



## 动画理解

![](../Animation/Animation.gif)

## 参考代码



## 复杂度分析