Skip to content

Commit 0b8ecf0

Browse files
committed
fix: update view for cli
1 parent 12de7de commit 0b8ecf0

File tree

8 files changed

+110
-4
lines changed

8 files changed

+110
-4
lines changed

bin/lc.js

+7
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {setQuestion} from "#common/utils/store/store-realm.js";
1717
import {getQuestionChineseName} from "#common/utils/question-handler/getQuestionChineseName.js";
1818
import {easyCreateView} from "#common/view/create.view.js";
1919
import {description} from "#resources/text/description.js";
20+
import {easyUpdateView} from "#common/view/update.view.js";
2021

2122
const version = process.env.VERSION??'0.0.0';
2223
program
@@ -29,6 +30,7 @@ program
2930
.option('-r, --random', 'Get a question randomly.')
3031
.option('-e, --easy', 'Use easy mode.')
3132
.option('-d, --directory <directory>', 'Set the question directory.')
33+
.option('-u, --update','Check the version to determine whether to update to the latest one.')
3234
.parse(process.argv)
3335

3436
const cmdArgs = program.args;
@@ -45,6 +47,11 @@ if(cmdOpts.easy){
4547
await easyCreateView();
4648
process.exit(0);;
4749
}
50+
// 检测更新
51+
if(cmdOpts.update){
52+
await easyUpdateView();
53+
process.exit(0);;
54+
}
4855
// 创建
4956
const create = (mode,question)=>{
5057
console.log(`MODE: ${mode}`);

bin/lk.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {getQuestionFileName} from "#common/utils/question-handler/getQuestionFil
1515
import {getQuestionChineseName} from "#common/utils/question-handler/getQuestionChineseName.js";
1616
import {easyCheckView} from "#common/view/check.view.js";
1717
import {description} from "#resources/text/description.js";
18+
import {easyUpdateView} from "#common/view/update.view.js";
1819

1920
const version = process.env.VERSION ?? '0.0.0';
2021
program
@@ -27,6 +28,7 @@ program
2728
.option('-r, --random', 'Check the last random question.')
2829
.option('-e, --easy', 'Use easy mode.')
2930
.option('-d, --directory <directory>', 'Set the question directory.')
31+
.option('-u, --update','Check the version to determine whether to update to the latest one.')
3032
.parse(process.argv)
3133

3234
const cmdArgs = program.args;
@@ -44,7 +46,11 @@ if (cmdOpts.easy) {
4446
await easyCheckView();
4547
process.exit(0);
4648
}
47-
//
49+
// 检测更新
50+
if(cmdOpts.update){
51+
await easyUpdateView();
52+
process.exit(0);;
53+
}
4854
// 检测函数
4955
const check = async (mode, question) => {
5056
const filePath = path.join(baseDir, getQuestionFileName(question), 'index.js');

common/utils/etc/update.js

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import https from "https";
22
import {rootPath} from "#common/utils/file/getRootPath.js";
33
import fs from "fs";
44
import path from "path";
5+
import { log } from "console";
56

67
const npmUrl = `https://registry.npmjs.org/leetcode-practice`;
78
const githubUrl = `https://api.github.com/repos/wh131462/leetcode-practice/commits?per_page=1`;
@@ -44,6 +45,7 @@ export const getGithubVersion = ()=>{
4445
});
4546
res.on('end', () => {
4647
try {
48+
console.log(data);
4749
const jsonData = JSON.parse(data);
4850
const latestCommitSha = jsonData[0].sha;
4951
console.log(latestCommitSha)

common/view/update.view.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ export const easyUpdateView = async()=>{
77
name:"willUpdate",
88
message:"检测到更新,是否进行更新?"
99
};
10-
getGithubVersion()
11-
const {localVersion,remoteVersion,isUpdate} = {};//await checkUpdate();
10+
const {localVersion,remoteVersion,isUpdate} = {};
1211
console.log(`当前最新版本为: ${remoteVersion}`);
1312
console.log(`本地版本为: ${localVersion}`);
1413
if(isUpdate){

docs/README_CN.md

+7
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,13 @@ npm run easy-fork
100100
### CLI的使用
101101

102102
#### lc
103+
##### 1. 帮助文档
104+
```shell
105+
lc -h
106+
```
107+
```shell
108+
109+
```
103110

104111
#### lk
105112

jsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"./common/*"
77
],
88
"#resources/*": [
9-
"#resources/*"
9+
"./resources/*"
1010
]
1111
}
1212
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<p>给定一个二叉搜索树, 找到该树中两个指定节点的最近公共祖先。</p>
2+
3+
<p><a href="https://baike.baidu.com/item/%E6%9C%80%E8%BF%91%E5%85%AC%E5%85%B1%E7%A5%96%E5%85%88/8918834?fr=aladdin" target="_blank">百度百科</a>中最近公共祖先的定义为:&ldquo;对于有根树 T 的两个结点 p、q,最近公共祖先表示为一个结点 x,满足 x 是 p、q 的祖先且 x 的深度尽可能大(<strong>一个节点也可以是它自己的祖先</strong>)。&rdquo;</p>
4+
5+
<p>例如,给定如下二叉搜索树:&nbsp; root =&nbsp;[6,2,8,0,4,7,9,null,null,3,5]</p>
6+
7+
<p><img alt="" src="https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2018/12/14/binarysearchtree_improved.png" style="height: 190px; width: 200px;"></p>
8+
9+
<p>&nbsp;</p>
10+
11+
<p><strong>示例 1:</strong></p>
12+
13+
<pre><strong>输入:</strong> root = [6,2,8,0,4,7,9,null,null,3,5], p = 2, q = 8
14+
<strong>输出:</strong> 6
15+
<strong>解释: </strong>节点 <code>2 </code>和节点 <code>8 </code>的最近公共祖先是 <code>6。</code>
16+
</pre>
17+
18+
<p><strong>示例 2:</strong></p>
19+
20+
<pre><strong>输入:</strong> root = [6,2,8,0,4,7,9,null,null,3,5], p = 2, q = 4
21+
<strong>输出:</strong> 2
22+
<strong>解释: </strong>节点 <code>2</code> 和节点 <code>4</code> 的最近公共祖先是 <code>2</code>, 因为根据定义最近公共祖先节点可以为节点本身。</pre>
23+
24+
<p>&nbsp;</p>
25+
26+
<p><strong>说明:</strong></p>
27+
28+
<ul>
29+
<li>所有节点的值都是唯一的。</li>
30+
<li>p、q 为不同节点且均存在于给定的二叉搜索树中。</li>
31+
</ul>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
2+
/**
3+
* 235.二叉搜索树的最近公共祖先 [2024-02-25]
4+
* 给定一个二叉搜索树, 找到该树中两个指定节点的最近公共祖先。
5+
* 百度百科中最近公共祖先的定义为:&ldquo;对于有根树 T 的两个结点 p、q,最近公共祖先表示为一个结点 x,满足 x 是 p、q 的祖先且 x 的深度尽可能大(一个节点也可以是它自己的祖先)。&rdquo;
6+
* 例如,给定如下二叉搜索树: root = [6,2,8,0,4,7,9,null,null,3,5]
7+
*
8+
* 示例 1:
9+
* 输入: root = [6,2,8,0,4,7,9,null,null,3,5], p = 2, q = 8
10+
* 输出: 6
11+
* 解释: 节点 2 和节点 8 的最近公共祖先是 6。
12+
* 示例 2:
13+
* 输入: root = [6,2,8,0,4,7,9,null,null,3,5], p = 2, q = 4
14+
* 输出: 2
15+
* 解释: 节点 2 和节点 4 的最近公共祖先是 2, 因为根据定义最近公共祖先节点可以为节点本身。
16+
*
17+
* 说明:
18+
* 所有节点的值都是唯一的。
19+
* p、q 为不同节点且均存在于给定的二叉搜索树中。
20+
*
21+
*/
22+
/**
23+
* Definition for a binary tree node.
24+
* function TreeNode(val) {
25+
* this.val = val;
26+
* this.left = this.right = null;
27+
* }
28+
*/
29+
30+
/**
31+
* @param {TreeNode} root
32+
* @param {TreeNode} p
33+
* @param {TreeNode} q
34+
* @return {TreeNode}
35+
*/
36+
var lowestCommonAncestor = function(root, p, q) {
37+
38+
};
39+
40+
/**
41+
* Test case
42+
*/
43+
showLogs(
44+
lowestCommonAncestor,
45+
{
46+
data: [[ [6,2,8,0,4,7,9,null,null,3,5], 2, 8],[ [6,2,8,0,4,7,9,null,null,3,5], 2, 4]],
47+
structure: ["TreeNode","TreeNode","TreeNode"],
48+
},
49+
{
50+
data: [ 6 , 2],
51+
structure: ["TreeNode"]
52+
}
53+
)
54+
console.log('点击跳转到题目提交:https://leetcode.cn/problems/lowest-common-ancestor-of-a-binary-search-tree/');

0 commit comments

Comments
 (0)