code: added doc code

This commit is contained in:
RiverTwilight 2023-01-02 18:57:26 +08:00
parent 3f00aa39fb
commit 2bd24e61a8
3 changed files with 50 additions and 35 deletions

View file

@ -3,19 +3,3 @@
* Created Time: 2023-01-02 * Created Time: 2023-01-02
* Author: RiverTwilight (contact@rene.wang) * Author: RiverTwilight (contact@rene.wang)
*/ */
function algorithm_A(n) {
console.log(0);
}
// 算法 B 时间复杂度:线性阶
function algorithm_B(n) {
for (var i = 0; i < n; i++) {
console.log(0);
}
}
// 算法 C 时间复杂度:常数阶
function algorithm_C(n) {
for (var i = 0; i < 1000000; i++) {
console.log(0);
}
}

View file

@ -3,20 +3,3 @@
* Created Time: 2023-01-02 * Created Time: 2023-01-02
* Author: RiverTwilight (contact@rene.wang) * Author: RiverTwilight (contact@rene.wang)
*/ */
// 算法 A 时间复杂度:常数阶
function algorithm_A(n: number): void {
console.log(0);
}
// 算法 B 时间复杂度:线性阶
function algorithm_B(n: number): void {
for (var i = 0; i < n; i++) {
console.log(0);
}
}
// 算法 C 时间复杂度:常数阶
function algorithm_C(n: number): void {
for (var i = 0; i < 1000000; i++) {
console.log(0);
}
}

View file

@ -233,7 +233,7 @@ $$
=== "JavaScript" === "JavaScript"
```js title="time_complexity.js" ```js title=""
// 算法 A 时间复杂度:常数阶 // 算法 A 时间复杂度:常数阶
function algorithm_A(n) { function algorithm_A(n) {
console.log(0); console.log(0);
@ -255,7 +255,7 @@ $$
=== "TypeScript" === "TypeScript"
```typescript title="time_complexity.ts" ```typescript title=""
// 算法 A 时间复杂度:常数阶 // 算法 A 时间复杂度:常数阶
function algorithm_A(n: number): void { function algorithm_A(n: number): void {
console.log(0); console.log(0);
@ -406,12 +406,32 @@ $$
=== "JavaScript" === "JavaScript"
```js title="" ```js title=""
function algorithm(n){
var a = 1; // +1
a += 1; // +1
a *= 2; // +1
// 循环 n 次
for(var i = 0; i < n; i++){ // +1
console.log(0) // +1
}
}
``` ```
=== "TypeScript" === "TypeScript"
```typescript title="" ```typescript title=""
function algorithm(n: number): void{
var a: number = 1; // +1
a += 1; // +1
a *= 2; // +1
// 循环 n 次
for(var i = 0; i < n; i++){ // +1
console.log(0) // +1
}
}
``` ```
@ -575,12 +595,40 @@ $$
=== "JavaScript" === "JavaScript"
```js title="" ```js title=""
function algorithm(n) {
var a = 1; // +0技巧 1
a = a + n; // +0技巧 1
// +n技巧 2
for (var i = 0; i < 5 * n + 1; i++) {
console.log(0);
}
// +n*n技巧 3
for (var i = 0; i < 2 * n; i++) {
for (var j = 0; j < n + 1; j++) {
console.log(0);
}
}
}
``` ```
=== "TypeScript" === "TypeScript"
```typescript title="" ```typescript title=""
function algorithm(n: number): void {
var a: number = 1; // +0技巧 1
a = a + n; // +0技巧 1
// +n技巧 2
for (var i = 0; i < 5 * n + 1; i++) {
console.log(0);
}
// +n*n技巧 3
for (var i = 0; i < 2 * n; i++) {
for (var j = 0; j < n + 1; j++) {
console.log(0);
}
}
}
``` ```