Skip to content

Commit 37c1097

Browse files
committed
Merge branch 'console-table' into dev
2 parents 7a4513a + fb3fadc commit 37c1097

File tree

6 files changed

+231
-2
lines changed

6 files changed

+231
-2
lines changed

common/utils/question-handler/showLogs.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import v8 from 'node:v8'
22
import { getFileSize } from '../functions/sizeUtil.js'
33
import { isSameData } from '../functions/isSameData.js'
44
import { setDataStructure } from './parseStructure.js'
5+
import { Table } from 'console-table-printer'
56

67
/**
78
* 执行并输出时间和内存
@@ -59,5 +60,18 @@ export function showLogs(fnName, paramMap, compareMap) {
5960
)
6061
logsItems.push(logItem)
6162
})
62-
console.table(logsItems)
63+
64+
const logTable = new Table({
65+
columns: [
66+
{ name: '测试结果', title: '测试结果', alignment: 'left', color: "blue" },
67+
{ name: '预期结果', title: '预期结果', alignment: 'left', maxLen: 10 },
68+
{ name: '执行结果', title: '执行结果', alignment: 'left', maxLen: 10 },
69+
{ name: '执行用时', title: '执行用时', alignment: 'left', color: "red" },
70+
{ name: '内存占用', title: '内存占用', alignment: 'left', color: "green" },
71+
]
72+
})
73+
logsItems.forEach((item) => {
74+
logTable.addRow(item)
75+
})
76+
logTable.printTable();
6377
}

package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"@inquirer/select": "^2.0.0",
4848
"chalk": "^5.3.0",
4949
"commander": "^12.0.0",
50+
"console-table-printer": "^2.12.0",
5051
"eslint-config-prettier": "^9.1.0",
5152
"eslint-plugin-prettier": "^5.1.3",
5253
"glob": "^10.3.10",
@@ -74,7 +75,10 @@
7475
"vitest": "^1.2.2"
7576
},
7677
"lint-staged": {
77-
"*": ["eslint", "prettier --write"]
78+
"*": [
79+
"eslint",
80+
"prettier --write"
81+
]
7882
},
7983
"config": {
8084
"commitizen": {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<p>给你一个下标从 <strong>0</strong> 开始的字符串 <code>word</code> ,长度为 <code>n</code> ,由从 <code>0</code> 到 <code>9</code> 的数字组成。另给你一个正整数 <code>m</code> 。</p>
2+
3+
<p><code>word</code> 的 <strong>可整除数组</strong> <code>div</code>&nbsp; 是一个长度为 <code>n</code> 的整数数组,并满足:</p>
4+
5+
<ul>
6+
<li>如果 <code>word[0,...,i]</code> 所表示的 <strong>数值</strong> 能被 <code>m</code> 整除,<code>div[i] = 1</code></li>
7+
<li>否则,<code>div[i] = 0</code></li>
8+
</ul>
9+
10+
<p>返回<em> </em><code>word</code> 的可整除数组。</p>
11+
12+
<p>&nbsp;</p>
13+
14+
<p><strong>示例 1:</strong></p>
15+
16+
<pre>
17+
<strong>输入:</strong>word = "998244353", m = 3
18+
<strong>输出:</strong>[1,1,0,0,0,1,1,0,0]
19+
<strong>解释:</strong>仅有 4 个前缀可以被 3 整除:"9"、"99"、"998244" 和 "9982443" 。
20+
</pre>
21+
22+
<p><strong>示例 2:</strong></p>
23+
24+
<pre>
25+
<strong>输入:</strong>word = "1010", m = 10
26+
<strong>输出:</strong>[0,1,0,1]
27+
<strong>解释:</strong>仅有 2 个前缀可以被 10 整除:"10" 和 "1010" 。
28+
</pre>
29+
30+
<p>&nbsp;</p>
31+
32+
<p><strong>提示:</strong></p>
33+
34+
<ul>
35+
<li><code>1 &lt;= n &lt;= 10<sup>5</sup></code></li>
36+
<li><code>word.length == n</code></li>
37+
<li><code>word</code> 由数字 <code>0</code> 到 <code>9</code> 组成</li>
38+
<li><code>1 &lt;= m &lt;= 10<sup>9</sup></code></li>
39+
</ul>

src/2575.find-the-divisibility-array-of-a-string/question.js

+55
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<p>给你两个正整数:<code>n</code> 和 <code>target</code> 。</p>
2+
3+
<p>如果数组 <code>nums</code> 满足下述条件,则称其为 <strong>美丽数组</strong> 。</p>
4+
5+
<ul>
6+
<li><code>nums.length == n</code>.</li>
7+
<li><code>nums</code> 由两两互不相同的正整数组成。</li>
8+
<li>在范围 <code>[0, n-1]</code> 内,<strong>不存在 </strong>两个 <strong>不同</strong> 下标 <code>i</code> 和 <code>j</code> ,使得 <code>nums[i] + nums[j] == target</code> 。</li>
9+
</ul>
10+
11+
<p>返回符合条件的美丽数组所可能具备的 <strong>最小</strong> 和,并对结果进行取模 <code>10<sup>9</sup>&nbsp;+ 7</code>。</p>
12+
13+
<p>&nbsp;</p>
14+
15+
<p><strong>示例 1:</strong></p>
16+
17+
<pre>
18+
<strong>输入:</strong>n = 2, target = 3
19+
<strong>输出:</strong>4
20+
<strong>解释:</strong>nums = [1,3] 是美丽数组。
21+
- nums 的长度为 n = 2 。
22+
- nums 由两两互不相同的正整数组成。
23+
- 不存在两个不同下标 i 和 j ,使得 nums[i] + nums[j] == 3 。
24+
可以证明 4 是符合条件的美丽数组所可能具备的最小和。</pre>
25+
26+
<p><strong>示例 2:</strong></p>
27+
28+
<pre>
29+
<strong>输入:</strong>n = 3, target = 3
30+
<strong>输出:</strong>8
31+
<strong>解释:</strong>
32+
nums = [1,3,4] 是美丽数组。
33+
- nums 的长度为 n = 3 。
34+
- nums 由两两互不相同的正整数组成。
35+
- 不存在两个不同下标 i 和 j ,使得 nums[i] + nums[j] == 3 。
36+
可以证明 8 是符合条件的美丽数组所可能具备的最小和。</pre>
37+
38+
<p><strong>示例 3:</strong></p>
39+
40+
<pre>
41+
<strong>输入:</strong>n = 1, target = 1
42+
<strong>输出:</strong>1
43+
<strong>解释:</strong>nums = [1] 是美丽数组。
44+
</pre>
45+
46+
<p>&nbsp;</p>
47+
48+
<p><strong>提示:</strong></p>
49+
50+
<ul>
51+
<li><code>1 &lt;= n &lt;= 10<sup>9</sup></code></li>
52+
<li><code>1 &lt;= target &lt;= 10<sup>9</sup></code></li>
53+
</ul>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
2+
/**
3+
* 3026.找出美丽数组的最小和 [2024-03-08]
4+
* 给你两个正整数:n 和 target 。
5+
* 如果数组 nums 满足下述条件,则称其为 美丽数组 。
6+
* nums.length == n.
7+
* nums 由两两互不相同的正整数组成。
8+
* 在范围 [0, n-1] 内,不存在 两个 不同 下标 i 和 j ,使得 nums[i] + nums[j] == target 。
9+
* 返回符合条件的美丽数组所可能具备的 最小 和,并对结果进行取模 109 + 7。
10+
*
11+
* 示例 1:
12+
* 输入:n = 2, target = 3
13+
* 输出:4
14+
* 解释:nums = [1,3] 是美丽数组。
15+
* - nums 的长度为 n = 2 。
16+
* - nums 由两两互不相同的正整数组成。
17+
* - 不存在两个不同下标 i 和 j ,使得 nums[i] + nums[j] == 3 。
18+
* 可以证明 4 是符合条件的美丽数组所可能具备的最小和。
19+
* 示例 2:
20+
* 输入:n = 3, target = 3
21+
* 输出:8
22+
* 解释:
23+
* nums = [1,3,4] 是美丽数组。
24+
* - nums 的长度为 n = 3 。
25+
* - nums 由两两互不相同的正整数组成。
26+
* - 不存在两个不同下标 i 和 j ,使得 nums[i] + nums[j] == 3 。
27+
* 可以证明 8 是符合条件的美丽数组所可能具备的最小和。
28+
* 示例 3:
29+
* 输入:n = 1, target = 1
30+
* 输出:1
31+
* 解释:nums = [1] 是美丽数组。
32+
*
33+
* 提示:
34+
* 1 <= n <= 109
35+
* 1 <= target <= 109
36+
*
37+
*/
38+
/**
39+
* @param {number} n
40+
* @param {number} target
41+
* @return {number}
42+
*/
43+
var minimumPossibleSum = function(n, target) {
44+
const mod = 1000000007;
45+
const m = Math.floor(target / 2);
46+
if (n <= m) return ((1 + n) * n / 2) % mod;
47+
return (((1 + m) * m / 2) + (((target + target + (n - m) - 1) * (n - m) / 2))) % mod;
48+
};
49+
50+
/**
51+
* Test case
52+
*/
53+
showLogs(
54+
minimumPossibleSum,
55+
{
56+
data: [[ 2, 3],[ 3, 3],[ 1, 1]],
57+
structure: ["number","number"],
58+
},
59+
{
60+
data: [4,8,1],
61+
structure: ["number"]
62+
}
63+
)
64+
console.log('点击跳转到题目提交:https://leetcode.cn/problems/find-the-minimum-possible-sum-of-a-beautiful-array/');

0 commit comments

Comments
 (0)