SSH 密钥
生成 SSH 密钥对
# 生成 Ed25519 密钥对(更先进)
ssh-keygen -t ed25519 -C "your_email@example.com"
# 生成 RSA 密钥对(兼容性好)
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
公钥部署到远程服务器
ssh-copy-id -i ~/.ssh/id_ed25519.pub user@remote_host
# 生成 Ed25519 密钥对(更先进)
ssh-keygen -t ed25519 -C "your_email@example.com"
# 生成 RSA 密钥对(兼容性好)
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
ssh-copy-id -i ~/.ssh/id_ed25519.pub user@remote_host
创建虚拟环境:
python3 -m venv .venv
激活虚拟环境:
source .venv/bin/activate
pip install
: 安装包pip uninstall
: 卸载包pip list
: 列出已安装包pip freeze
: 列出已安装包及精确版本(适合生成requirements.txt
,例如pip freeze > requirements.txt
、pip install -r requirements.txt
)pip show
: 查看某个包的元信息pip check
: 检测已安装包依赖是否有冲突pip search
: 在 PyPI 上搜索包pip download
: 仅下载包压缩文件到当前目录,不安装pip wheel
: 构建 wheel 包(生成.whl
文件),用于离线安装Leetcode 3202. 找出有效子序列的最大长度 II
from typing import List
class Solution:
def maximumLength(self, nums: List[int], k: int) -> int:
f = [[0] * k for _ in range(k)]
for x in nums:
x %= k
for y, fxy in enumerate(f[x]):
f[y][x] = fxy + 1
return max(map(max, f))
print(Solution().maximumLength([1, 2, 3, 4, 5], 2))
声明m
行n
列二维数组:matrix = [[0] * n for _ in range(m)]
函数map(function, iterable)
:第一个参数为应用于每个元素的函数,第二个参数为可迭代对象
class Solution:
def numIdenticalPairs(self, nums: List[int]) -> int:
ans = 0
cnt = collections.defaultdict(int)
for j, x in enumerate(nums):
if x in cnt:
ans += cnt[x]
cnt[x] += 1
return ans
class Solution:
"""
方法一:枚举右维护左
时间复杂度O(n)
空间复杂度O(n)
"""
def interchangeableRectangles(self, rectangles: List[List[int]]) -> int:
ans = 0
cnt = collections.defaultdict(int)
for j, matrix in enumerate(rectangles):
if matrix[0] / matrix[1] in cnt:
ans += cnt[matrix[0] / matrix[1]]
cnt[matrix[0] / matrix[1]] += 1
return ans
class Solution:
def numEquivDominoPairs(self, dominoes: List[List[int]]) -> int:
ans = 0
cnt = collections.defaultdict(int)
for j, x in enumerate(dominoes):
# 列表list是不可哈希的,所以用元组tuple
if (x[0], x[1]) in cnt:
ans += cnt[(x[0], x[1])]
if x[0] != x[1] and (x[1], x[0]) in cnt:
ans += cnt[(x[1], x[0])]
cnt[(x[0], x[1])] += 1
return ans
上述很多例题都可以用组合数学技巧优化(求...共有几对),不再赘述。
Pandoc 是一个文档转换工具,可以实现 md
转 docx
或 pdf
。
Sudo pacman -Syu pandoc
使用 Tex 的核心组件,安装 Arch Linux 中的包组 texlive
即可。
sudo pacman -Syu texlive
编写 test.tex
文件:
\documentclass{article}
\begin{document}
Hello World!
\end{document}
编译:
latex test.tex
查看:
xdvi test.dvi
也可以直接生成 pdf
文件:
pdflatex test.tex
详细教程参考WIKI
创建了一个样例文件 sample.md
:
# Sample Markdown Document
This is a **comprehensive sample** of Markdown syntax to test conversion tools like *Pandoc*. It includes headings, lists, code, blockquotes, tables, links, images, footnotes, math, and more.
---
## Table of Contents
1. [Headings](#headings)
2. [Text Formatting](#text-formatting)
3. [Lists](#lists)
4. [Blockquotes](#blockquotes)
5. [Code](#code)
6. [Tables](#tables)
7. [Links & Images](#links--images)
8. [Footnotes](#footnotes)
9. [Horizontal Rules](#horizontal-rules)
10. [Math](#math)
11. [HTML](#html)
12. [Task Lists](#task-lists)
---
## Headings
# H1 Heading
## H2 Heading
### H3 Heading
#### H4 Heading
##### H5 Heading
###### H6 Heading
---
## Text Formatting
- **Bold**
- *Italic*
- ***Bold and Italic***
- ~~Strikethrough~~
- <u>Underline (via HTML)</u>
- ==Highlight (not native, Pandoc-supported)==
- `Inline code`
---
## Lists
### Unordered List
- Item A
- Subitem A.1
- Sub-subitem A.1.a
- Item B
### Ordered List
1. First item
2. Second item
a. Subitem
b. Another subitem
3. Third item
---
## Blockquotes
> This is a blockquote.
>
> > Nested blockquote.
>
> Another line in the same quote.
---
## Code
### Inline Code
Use the `printf()` function.
### Fenced Code Blocks
def greet(name):
print(f"Hello, {name}!")
echo "Hello, world"
console.log("Hello, JavaScript!");
---
## Tables
| Syntax | Description | Output |
|--------|-------------|--------|
| Header | Title | Text |
| `code` | *Italic* | **Bold** |
Right-aligned:
| ID | Name | Score |
|----|---------|------:|
| 1 | Alice | 90 |
| 2 | Bob | 85 |
| 3 | Charlie | 95 |
---
## Links & Images
### Link
[OpenAI](https://www.openai.com)
<https://www.example.com>
### Image

---
## Footnotes
Here is a sentence with a footnote.[^1]
[^1]: This is the footnote definition.
---
## Horizontal Rules
---
---
## Math
Inline: $E = mc^2$
Block:
$$
\int_0^\infty e^{-x^2} dx = \frac{\sqrt{\pi}}{2}
$$
---
## HTML
<div style="color: blue;">
This is an HTML block inside Markdown.
</div>
---
## Task Lists
- [x] Write a sample file
- [x] Include all major syntax
- [ ] Test with Pandoc
- [ ] Export to PDF/HTML/Docx
---
_End of document._
---
## 中文测试段落
这是一个用于测试 **Pandoc** 是否支持中文的段落。
中文支持对于中文用户来说非常重要。你可以尝试将此文档导出为 PDF 或 DOCX,看看字体是否正常显示、排版是否美观。
以下是一些常见的中文格式测试:
- **加粗文字**
- *斜体文字*
- ~~删除线文字~~
- `行内代码`
### 中文列表
1. 第一步:安装 Pandoc;
2. 第二步:准备 Markdown 文件;
3. 第三步:运行转换命令。
- 项目 A
- 子项目 A.1
- 项目 B
### 中文段落示例
在很久很久以前,有一个叫做 Markdown 的标记语言,它简洁、优雅、易于使用。在中文世界中,它也越来越受欢迎。
> “生活就像一盒巧克力,你永远不知道你会得到什么。” ——《阿甘正传》
---
_测试结束。_
直接转换成 pdf
,显示效果可能不太好。
pandoc -o sample.pdf sample.md
在网上抄来的一套配置,首先在根目录创建 head.tex
:
\usepackage[top=2cm, bottom=1.5cm, left=2cm, right=2cm]{geometry}
% change background color for inline code in
% markdown files. The following code does not work well for
% long text as the text will exceed the page boundary
\definecolor{bgcolor}{HTML}{E0E0E0}
\let\oldtexttt\texttt
\renewcommand{\texttt}[1]{
\colorbox{bgcolor}{\oldtexttt{#1}}
}
\XeTeXlinebreaklocale "zh"
\XeTeXlinebreakskip = 0pt plus 1pt minus 0.1pt
\usepackage[top=2cm, bottom=1.5cm, left=2cm, right=2cm]{geometry}
% Change the default style of block quote
\usepackage{framed}
\usepackage{quoting}
\definecolor{bgcolor}{HTML}{DADADA}
\colorlet{shadecolor}{bgcolor}
% define a new environment shadedquotation. You can change leftmargin and
% rightmargin as you wish.
\newenvironment{shadedquotation}
{\begin{shaded*}
\quoting[leftmargin=1em, rightmargin=0pt, vskip=0pt, font=itshape]
}
{\endquoting
\end{shaded*}
}
%
\def\quote{\shadedquotation}
\def\endquote{\endshadedquotation}
随后使用命令:
pandoc --pdf-engine=xelatex -V mainfont='Source Han Serif CN' --highlight-style tango -V colorlinks=true -o output.pdf sample.md -H head.tex
效果稍微好一点。