code: added code for time complexity chapter

pull/196/head
RiverTwilight 2 years ago
parent c94101a365
commit 3f00aa39fb

@ -0,0 +1,21 @@
/**
* File: time_complexity.js
* Created Time: 2023-01-02
* 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);
}
}

@ -0,0 +1,22 @@
/**
* File: time_complexity.ts
* Created Time: 2023-01-02
* 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);
}
}

@ -233,7 +233,7 @@ $$
=== "JavaScript" === "JavaScript"
```js title="" ```js title="time_complexity.js"
// 算法 A 时间复杂度:常数阶 // 算法 A 时间复杂度:常数阶
function algorithm_A(n) { function algorithm_A(n) {
console.log(0); console.log(0);
@ -255,7 +255,7 @@ $$
=== "TypeScript" === "TypeScript"
```typescript title="" ```typescript title="time_complexity.ts"
// 算法 A 时间复杂度:常数阶 // 算法 A 时间复杂度:常数阶
function algorithm_A(n: number): void { function algorithm_A(n: number): void {
console.log(0); console.log(0);

Loading…
Cancel
Save