Skip to content

Commit b5ca1a0

Browse files
author
lucifer
committed
feat: 复杂度速查
1 parent 0a91623 commit b5ca1a0

File tree

7 files changed

+401
-98
lines changed

7 files changed

+401
-98
lines changed

‎src/App.js

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import checkUpdate from "./checkUpdates";
2020
import "antd/dist/antd.css";
2121
import "./App.css";
2222
import CodeTemplates from "./codeTemplates/codeTemplate";
23+
import ComplexityRating from './complexityRating/index'
2324
// import { data as a } from "./db/binary-tree";
2425

2526
const { problems, selected } = db;
@@ -195,6 +196,9 @@ function App() {
195196
<TabPane key="app" tab="代码模板">
196197
<CodeTemplates page={page} tempaltes={tempaltes}></CodeTemplates>
197198
</TabPane>
199+
<TabPane key="complexityRating" tab="复杂度速查">
200+
<ComplexityRating />
201+
</TabPane>
198202
<TabPane key="roadmap" tab="学习路线">
199203
<Roadmap />
200204
</TabPane>

‎src/codeTemplates/codeTemplate.jsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import {
1111
const { TabPane } = Tabs;
1212
const { Panel } = Collapse;
1313

14-
export default function CodeTemplate({ page, tempaltes }) {
14+
export default function CodeTemplate({ tempaltes }) {
1515
return (
16-
<div style={page === "" ? {} : { display: "none" }}>
16+
<div >
1717
<Tabs>
1818
{tempaltes.map((tempalte) => (
1919
<TabPane

‎src/complexityRating/index.jsx

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import React from "react";
2+
import { Button, Table } from "antd";
3+
4+
import "./index.less";
5+
6+
// | 数据规模 | 算法可接受时间复杂度 |
7+
// | -------- | -------------------- |
8+
// | <= 10 | $O(n!)$ |
9+
// | <=20 | $O(2^n)$ |
10+
// | <=100 | $O(n^4)$ |
11+
// | <=500 | $O(n^3)$ |
12+
// | <=2500 | $O(n^2)$ |
13+
// | <=10^6 | $O(n * logn)$ |
14+
// | <=10^7 | $O(n)$ |
15+
// | <=10^14 | $O(\sqrt{n})$ |
16+
// | - | $O(logn)$ |
17+
18+
const columns = [
19+
{
20+
key: "size",
21+
dataIndex: "size",
22+
title: "数据规模",
23+
align: "center",
24+
},
25+
{
26+
key: "complexity",
27+
dataIndex: "complexity",
28+
title: "算法可接受时间复杂度",
29+
align: "center",
30+
render: (t) => {
31+
if (t === "O(sqrt(n))") return <img src={require("../imgs/sqrt.svg")} />;
32+
return t;
33+
},
34+
},
35+
];
36+
37+
const data = [
38+
{
39+
size: "<= 10",
40+
complexity: "O(n!)",
41+
},
42+
{
43+
size: "<= 20",
44+
complexity: "O(2^n)",
45+
},
46+
{
47+
size: "<= 100",
48+
complexity: "O(n^4)",
49+
},
50+
{
51+
size: "<= 500",
52+
complexity: "O(n^3)",
53+
},
54+
{
55+
size: "<= 2500",
56+
complexity: "O(n^2)",
57+
},
58+
{
59+
size: "<= 10^6",
60+
complexity: "O(nlogn)",
61+
},
62+
{
63+
size: "<= 10^7",
64+
complexity: "n",
65+
},
66+
{
67+
size: "<= 10^14",
68+
complexity: "O(sqrt(n))",
69+
},
70+
{
71+
size: "-",
72+
complexity: "O(logn)",
73+
},
74+
];
75+
76+
export default function ComplexityRating({}) {
77+
return (
78+
<div>
79+
<Button
80+
type="link"
81+
href="https://lucifer.ren/blog/2020/12/21/shuati-silu3/"
82+
target="_blank"
83+
>
84+
不懂为什么?点这里
85+
</Button>
86+
87+
<div>
88+
<img src="https://tva1.sinaimg.cn/large/0081Kckwly1gm6x8pzqotj30ad03q3ye.jpg" />
89+
</div>
90+
91+
<Table columns={columns} dataSource={data} />
92+
</div>
93+
);
94+
}

‎src/complexityRating/index.less

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.blockquote {
2+
text-size-adjust: 100%;
3+
line-height: 1.55em;
4+
font-weight: 400;
5+
border-radius: 6px;
6+
color: #595959;
7+
font-style: normal;
8+
text-align: left;
9+
box-sizing: inherit;
10+
border-left: none;
11+
border: 1px solid RGBA(64, 184, 250, 0.4);
12+
background: RGBA(64, 184, 250, 0.1);
13+
}

‎src/contentScript.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,14 @@ function normalize(testCase) {
6868
}
6969

7070
function extractTestCase(text, prefix) {
71-
const testCase = text.match(new RegExp(`${prefix}(.*)输出`, "s"));
72-
if (!testCase || testCase.length <= 1) {
73-
return text.match(new RegExp(`${prefix}(.*)$`, "s"));
71+
const possiblePrefixs = ["输出", "返回", ""];
72+
for (let tag of possiblePrefixs) {
73+
const testCase = text.match(new RegExp(`${prefix}(.*)${tag}`, "s"));
74+
if (testCase && testCase.length > 1) {
75+
return testCase;
76+
}
7477
}
75-
return testCase;
78+
return [];
7679
}
7780

7881
function getProviedTestCases() {

0 commit comments

Comments
 (0)