Skip to content

Commit 0806ab9

Browse files
committed
feat:2696 & 创建脚本和检测脚本
1 parent 82858c3 commit 0806ab9

14 files changed

+194
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
yarn.lock
3+
.idea

.idea/.gitignore

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/jsLibraryMappings.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/leetcode-practice.iml

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

common/check.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* 执行脚本
3+
*/
4+
const {temExe} = require('./utils/temExe');
5+
temExe('node ./src/{0}/index.js')
6+
.then(res=>console.log(`执行结果:\n${res}`))
7+
.catch(e=>console.log("执行报错: ",e));

common/create.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* 工作区为 根目录
3+
*/
4+
const fs = require("fs");
5+
const {temExe} = require("./utils/temExe");
6+
7+
const args = process.argv.slice(2);
8+
const path = args[0];
9+
// 判断是否存在
10+
fs.exists(`./src/${path}`, (exists) => {
11+
if (exists) {
12+
console.log(`./src/${path} 已存在,请检查目录!`);
13+
return;
14+
}
15+
temExe('mkdir -p ./src/{0} && cp ./common/template/template.js ./src/{0}/index.js')
16+
.then(() => console.log(`创建成功`))
17+
.catch(e => console.log("创建报错: ", e));
18+
})
19+

common/template/template.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* @题目
3+
*
4+
* @描述:
5+
*
6+
*/
7+
const test = () => {
8+
9+
};
10+
/**
11+
* Test case
12+
*/
13+
console.log(test());

common/utils/temExe.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const {exec} = require('child_process');
2+
3+
/**
4+
* 执行模板指令 接受外部变量
5+
* 在调用的地方 获取外部参数 传入模板参数
6+
* @param temCommand
7+
* @param args
8+
* @returns {Promise<unknown>}
9+
*/
10+
function temExe(temCommand, ...args) {
11+
!args?.length && (args = process.argv?.slice(2));
12+
return new Promise((resolve, reject) => {
13+
const command = temCommand.replace(/\{\d+}/g, (match) => {
14+
const argIndex = Number(match.slice(1, -1));
15+
return args[argIndex];
16+
});
17+
exec(command, (error, stdout, stderr) => {
18+
if (error) {
19+
reject(error.message);
20+
} else if (stderr) {
21+
reject(stderr);
22+
} else {
23+
resolve(stdout);
24+
}
25+
});
26+
})
27+
}
28+
29+
module.exports = {temExe}

node_modules/.yarn-integrity

+16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "leetcode-practice",
3+
"version": "1.0.0",
4+
"description": "A leetcode practice project",
5+
"main": "index.js",
6+
"type": "commonjs",
7+
"scripts": {
8+
"leet-check": "node common/check.js",
9+
"leet-create": "node common/create.js"
10+
},
11+
"author": "EternalHeart",
12+
"license": "ISC",
13+
"dependencies": {
14+
}
15+
}

src/2696/index.js

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* 删除子串后的字符串最小长度
3+
* 给你一个仅由 大写 英文字符组成的字符串 s 。
4+
* 你可以对此字符串执行一些操作,在每一步操作中,你可以从 s 中删除 任一个 "AB" 或 "CD" 子字符串。
5+
* 通过执行操作,删除所有 "AB" 和 "CD" 子串,返回可获得的最终字符串的 最小 可能长度。
6+
* 注意,删除子串后,重新连接出的字符串可能会产生新的 "AB" 或 "CD" 子串。
7+
*
8+
* 示例 1:
9+
*
10+
* 输入:s = "ABFCACDB"
11+
* 输出:2
12+
* 解释:你可以执行下述操作:
13+
* - 从 "ABFCACDB" 中删除子串 "AB",得到 s = "FCACDB" 。
14+
* - 从 "FCACDB" 中删除子串 "CD",得到 s = "FCAB" 。
15+
* - 从 "FCAB" 中删除子串 "AB",得到 s = "FC" 。
16+
* 最终字符串的长度为 2 。
17+
* 可以证明 2 是可获得的最小长度。
18+
* 示例 2:
19+
*
20+
* 输入:s = "ACBBD"
21+
* 输出:5
22+
* 解释:无法执行操作,字符串长度不变。
23+
*
24+
* 提示:
25+
* 1 <= s.length <= 100
26+
* s 仅由大写英文字母组成
27+
* @param s
28+
* @returns {*}
29+
*/
30+
var minLength = function(s) {
31+
const useStack = [];
32+
const check = (a,b)=>["AB","CD"].includes(a+b);
33+
for(const i of s){
34+
if(check(useStack.at(-1),i)){
35+
useStack.pop();
36+
}else{
37+
useStack.push(i);
38+
}
39+
}
40+
return useStack.length;
41+
};
42+
43+
/**
44+
* Test case
45+
*/
46+
console.log(minLength("ABFCACDB"))
47+
console.log(minLength("ACBBD"))

yarn.lock

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2+
# yarn lockfile v1
3+
4+
5+
process@^0.11.10:
6+
version "0.11.10"
7+
resolved "http://npm.runtongqiuben.com/process/-/process-0.11.10.tgz#7332300e840161bda3e69a1d1d91a7d4bc16f182"
8+
integrity sha512-cdGef/drWFoydD1JsMzuFf8100nZl+GT+yacc2bEced5f9Rjk4z+WtFUTBu9PhOi9j/jfmBPu0mMEY4wIdAF8A==

0 commit comments

Comments
 (0)