Skip to content

Commit 48e6bf7

Browse files
authored
Feat: sword means offer: 64-sum-1-n-nums (#23)
* feat: plop new docs or template set alias; update docs about alias * feat: sword means offer: 03 find repeat number; fix: plop template; readme title * fix: remove changelog at pre commit * feat: sword means offer: 64-sum-1-n-nums * fix: plop docs code path; changelog; feat: editorconfig
1 parent 16d4263 commit 48e6bf7

File tree

11 files changed

+145
-12
lines changed

11 files changed

+145
-12
lines changed

.editorconfig

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# http://editorconfig.org
2+
# https://github.com/editorconfig/editorconfig/wiki/EditorConfig-Properties
3+
4+
# 表示是最顶层的配置文件, 发现设为true时, 才会停止查找.editorconfig文件
5+
root = true
6+
7+
[*]
8+
# tab space
9+
indent_style = tab
10+
11+
indent_size = 2
12+
# 设置换行符, 值为lf, cr, crlf
13+
end_of_line = lf
14+
charset = utf-8
15+
16+
# 用一个整数来设置tab缩进的列数。默认是indent_size
17+
tab_width = indent_size
18+
19+
#是否删除行尾的空格
20+
trim_trailing_whitespace = true
21+
22+
#是否在文件的最后插入一个空行
23+
insert_final_newline = true
24+
25+
[*.md]
26+
indent_size = 2
27+
trim_trailing_whitespace = false
28+
insert_final_newline = true
29+
30+
[Makefile]
31+
indent_style = tab

CHANGELOG.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
# 1.0.0 (2020-07-26)
1+
# 1.0.0 (2020-07-29)
22

33

44
### Bug Fixes
55

66
* algorithms docs build bug ([c4ed72d](https://github.com/Rain120/awesome-javascript-code-implementation/commit/c4ed72d2da7b0f940a4f7530bdfaaa47631741ff))
7-
* changelog not add ([d69f43f](https://github.com/Rain120/awesome-javascript-code-implementation/commit/d69f43f5112ea7d55242b46ca670ad54741bd940))
87
* ci bug ([f6185d6](https://github.com/Rain120/awesome-javascript-code-implementation/commit/f6185d6f29e1587bba76f0772433441602bc8db7))
98
* deploy bug ([568b663](https://github.com/Rain120/awesome-javascript-code-implementation/commit/568b663a5fd6d1b4ab40043e0a693564d7dc3a84))
109
* gitalk cannot login; feat: manifest ([ee9e237](https://github.com/Rain120/awesome-javascript-code-implementation/commit/ee9e237314451244a13c6c4c13f8a119572b6ecb))
@@ -14,7 +13,9 @@
1413
* math docs menu ([3958b99](https://github.com/Rain120/awesome-javascript-code-implementation/commit/3958b99b27170aa419b4b8983d7cf62cbae6b724))
1514
* netlify deploy bug ([f1830e9](https://github.com/Rain120/awesome-javascript-code-implementation/commit/f1830e9a07d27b4d6b9c3c67e13272e9064bb322))
1615
* plop create code and docs model(plop name bug) ([8ef0e62](https://github.com/Rain120/awesome-javascript-code-implementation/commit/8ef0e627daadc21842de8a35495c345f9ca70550))
16+
* plop docs code path; changelog; feat: editorconfig ([27073f0](https://github.com/Rain120/awesome-javascript-code-implementation/commit/27073f0aee4027321e798b0d48d900a686df5326))
1717
* readme selected; package.json husky add test ([b228b61](https://github.com/Rain120/awesome-javascript-code-implementation/commit/b228b6194832f909c0b3c7a0c38843bab3b7c63d))
18+
* remove changelog at pre commit ([c49bf26](https://github.com/Rain120/awesome-javascript-code-implementation/commit/c49bf2667ff411786de3bb2442a6a4b8af9a0083))
1819

1920

2021
### Features
@@ -52,20 +53,22 @@
5253
* plop create code and docs model ([2dece76](https://github.com/Rain120/awesome-javascript-code-implementation/commit/2dece76fbfd83514551dbabadf7c54d73674730d))
5354
* plop new code and docs template ([61a936b](https://github.com/Rain120/awesome-javascript-code-implementation/commit/61a936b58bc52a1cf984dc6156746b43f65da7f1))
5455
* plop new docs or template set alias; update docs about alias ([3722bcc](https://github.com/Rain120/awesome-javascript-code-implementation/commit/3722bccea8605dfef55dd270e7f2ca14a1c03ae7))
56+
* plop new docs or template set alias; update docs about alias ([#21](https://github.com/Rain120/awesome-javascript-code-implementation/issues/21)) ([4334218](https://github.com/Rain120/awesome-javascript-code-implementation/commit/4334218a4ca6635a107fe3baf2d0a17fe3e7458b))
5557
* promise; debugger launch ([cc8ad80](https://github.com/Rain120/awesome-javascript-code-implementation/commit/cc8ad803956e65431cedd97f1ebb333ffe78c28e))
5658
* proxy design ([e615f39](https://github.com/Rain120/awesome-javascript-code-implementation/commit/e615f39497043f4c2357c7366cb13226b57208e6))
5759
* sort -> bubbleSort(algorithm, readme, test) ([36fab7b](https://github.com/Rain120/awesome-javascript-code-implementation/commit/36fab7b029d425ac129b6c4f202b18a9a3852fef))
5860
* sort -> bucket, radix; algorithm -> binaryTree; add some types; docs: update readme; fix: tests format, ([b1d166c](https://github.com/Rain120/awesome-javascript-code-implementation/commit/b1d166c7e56e37f35ab0bc7628186eeae15a4b60))
5961
* sword means offer: 03 find repeat number; fix: plop template; readme title ([cf084d8](https://github.com/Rain120/awesome-javascript-code-implementation/commit/cf084d80099aa5445bd6522a6d8be373ad2c73fb))
62+
* sword means offer: 64-sum-1-n-nums ([9e09cf8](https://github.com/Rain120/awesome-javascript-code-implementation/commit/9e09cf87198dfe22129ae7118e7d24966b235972))
6063
* update docs -> algorithm: binary tree, sort ([5d57bc4](https://github.com/Rain120/awesome-javascript-code-implementation/commit/5d57bc4489551bffeca34102f2fce61b59996873))
6164
* update docs -> design pattern function array object math primitive types utils ([1690af5](https://github.com/Rain120/awesome-javascript-code-implementation/commit/1690af5ed96c46341465f72866732837e5c72200))
6265
* update netlify status ([013b5ca](https://github.com/Rain120/awesome-javascript-code-implementation/commit/013b5ca5847873adabbff93a89daa41500ccf153))
6366
* update readme for plans ([b427b96](https://github.com/Rain120/awesome-javascript-code-implementation/commit/b427b9667cc97c77df75ef0af56eb84b6b4c3ba6))
6467
* update test.yml -> ci.yml and set command ([43b96b6](https://github.com/Rain120/awesome-javascript-code-implementation/commit/43b96b63fc2788a5ea37fa7567c6a6dced4b875f))
6568
* update vdom-diff docs ([06590c5](https://github.com/Rain120/awesome-javascript-code-implementation/commit/06590c56d0df7cbba68bb705cb7e159f6f765c3a))
6669
* update xmind ([cb23933](https://github.com/Rain120/awesome-javascript-code-implementation/commit/cb23933f46152c59a7b08f84d7355b35bba25002))
67-
* update xmind ([71317c6](https://github.com/Rain120/awesome-javascript-code-implementation/commit/71317c67376bc8196f80e25391adfdc9b2496380))
6870
* update xmind ([408ca68](https://github.com/Rain120/awesome-javascript-code-implementation/commit/408ca685142dc425e90be64a284016d57d580893))
71+
* update xmind ([71317c6](https://github.com/Rain120/awesome-javascript-code-implementation/commit/71317c67376bc8196f80e25391adfdc9b2496380))
6972
* update xmind ([4256758](https://github.com/Rain120/awesome-javascript-code-implementation/commit/4256758c5fe0a036ce3ececc43f848e48964d7a0))
7073
* update: plans; fix: readme bug ([d44e559](https://github.com/Rain120/awesome-javascript-code-implementation/commit/d44e559def7834fcccbb19797a1d29bf5cc4e5b7))
7174
* vdom diff algorithm ([3b7779d](https://github.com/Rain120/awesome-javascript-code-implementation/commit/3b7779dcad7e184027d1bddfa6387224c2f009d3))

docs/.vuepress/utils/alias.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,6 @@
5454
"shellSort": "希尔排序",
5555
"sword-means-offer-------": "",
5656
"sword-means-offer": "剑指 Offer",
57-
"03-find-repeat-number": "03. 数组中重复的数字"
58-
}
57+
"03-find-repeat-number": "03. 数组中重复的数字",
58+
"64-sum-1-n-nums": "64 求1 ~ n的和"
59+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
### 题目描述
2+
3+
`1 + 2 + ... + n` , 要求 **不能使用** `乘除法`, `for`, `while`, `if`, `else`, `switch`, `case` 等关键字及条件判断语句 `(A ? B : C)`
4+
 
5+
6+
示例 1:
7+
8+
```
9+
输入: n = 3
10+
输出: 6
11+
```
12+
13+
示例 2:
14+
```
15+
输入: n = 9
16+
输出: 45
17+
```
18+
19+
限制:
20+
21+
```
22+
1 <= n <= 10000
23+
```
24+
25+
来源: [力扣 (LeetCode)](https://leetcode-cn.com/problems/qiu-12n-lcof)
26+
27+
## 解题思路 or 实现原理
28+
29+
我们小学就学过 `1 + 2 + ... + n` 的结果就是 $ sum = \frac{(1 + n) * n}{2} $, 但是由于题目限定, 我们不能使用常规方法, 所以我们可以通过 **短路递归****幂运算移位** 来计算出结果。
30+
31+
## 实现代码
32+
33+
<<< @/src/sword-means-offer/64-sum-1-n-nums/index.ts

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
},
4949
"husky": {
5050
"hooks": {
51-
"pre-commit": "npm run deploy && lint-staged",
51+
"pre-commit": "npm run changelog && npm run deploy && git add . && lint-staged",
5252
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
5353
}
5454
},

plop-templates/code/README.md.hbs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
### 解题思路 or 实现原理
1+
## 题目描述
22

3-
### 参考
3+
## 解题思路 or 实现原理
4+
5+
## 参考

plop-templates/docs/zh/README.md.hbs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
## 题目描述
2+
13
## 解题思路 or 实现原理
24

35
## 实现代码
46

5-
<<< @/{{path}}/{{name}}/index.ts
7+
<<< @/{{templatePath}}/{{name}}/index.ts
68

79
## 参考
8-

src/sword-means-offer/03-find-repeat-number/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## 题目
1+
## 题目描述
22

33
找出数组中重复的数字。
44

@@ -12,7 +12,6 @@
1212
[2, 3, 1, 0, 2, 5, 3]
1313
输出: 2 或 3
1414
```
15-
 
1615

1716
限制:
1817

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
### 题目描述
2+
3+
`1 + 2 + ... + n` , 要求 **不能使用** `乘除法`, `for`, `while`, `if`, `else`, `switch`, `case` 等关键字及条件判断语句 `(A ? B : C)`
4+
 
5+
6+
示例 1:
7+
8+
```
9+
输入: n = 3
10+
输出: 6
11+
```
12+
13+
示例 2:
14+
```
15+
输入: n = 9
16+
输出: 45
17+
```
18+
19+
限制:
20+
21+
1 <= n <= 10000
22+
23+
来源: [力扣 (LeetCode)](https://leetcode-cn.com/problems/qiu-12n-lcof)
24+
25+
## 解题思路 or 实现原理
26+
27+
我们小学就学过 `1 + 2 + ... + n` 的结果就是 $ sum = \frac{(1 + n) * n}{2} $, 但是由于题目限定, 我们不能使用常规方法, 所以我们可以通过 **短路递归****幂运算移位** 来计算出结果。
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* @Author: Rainy
3+
* @Date: 2020-02-06 19:05:18
4+
* @LastEditors: Rainy
5+
* @LastEditTime: 2020-07-28 15:46:52
6+
*/
7+
8+
import { sumNums_1, sumNums_2 } from '.';
9+
10+
test('Test 64-sum-1-n-nums', () => {
11+
expect(sumNums_1(3)).toBe(6);
12+
});
13+
14+
test('Test 64-sum-1-n-nums', () => {
15+
expect(sumNums_2(3)).toBe(6);
16+
});
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* @Author: Rainy
3+
* @Date: 2019-11-14 19:25:01
4+
* @LastEditors: Rainy
5+
* @LastEditTime: 2020-07-28 15:42:46
6+
*/
7+
8+
/**
9+
* @param {number} n
10+
* @return {number}
11+
*/
12+
export function sumNums_1(n: number): number {
13+
return n && (n + sumNums_1(--n));
14+
};
15+
16+
export function sumNums_2(n: number): number {
17+
// (n + 1) * n / 2 => (n ^ 2 + n) / 2
18+
return (n ** 2 + n) >> 1;
19+
};
20+

0 commit comments

Comments
 (0)