Skip to content

Commit

Permalink
feat: 0402
Browse files Browse the repository at this point in the history
  • Loading branch information
niaogege committed Apr 2, 2024
1 parent a77f9df commit b7eabaf
Show file tree
Hide file tree
Showing 9 changed files with 238 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ nav:
> 练习的不是手写,而是对于这份工作的热爱
> base 50 middle 30 hard 20
> base 50 middle 30 hard 20 total 100
# 最热的手写,没有之一,没有准备好,就不要出去面试

Expand Down Expand Up @@ -643,7 +643,7 @@ lodashGet(test, 'other[0].name');
function lodashSet(obj, path, val) {}
```

## 23.场景应用题:红绿灯问题
## 23.场景应用题, 红绿灯问题

```js
function red() {
Expand Down Expand Up @@ -1074,7 +1074,7 @@ Number.prototype.minus = function (n) {
(5).add(3).minus(2);
```

## 39.要求设计 LazyMan 类,实现以下功能
## 39.场景应用题,要求设计 LazyMan 类,实现以下功能

> [要求设计 LazyMan 类,实现以下功能](https://github.com/Advanced-Frontend/Daily-Interview-Question/issues/98)
Expand Down Expand Up @@ -1202,14 +1202,94 @@ swr('cache', MockPromise, 1000);

## 42.如何自定义一个事件,使某一个对象能够捕获到?

## 43.
```js

```

## 43.实现一个 node 异步函数的 promisify

```js
function promisify(fn) {
return (...arr) =>
new Promise((resolve, reject) => {
arr.push((err, ...val) => {
if (err) {
reject(err);
} else {
resolve(val);
}
});
fn.apply(this, arr);
});
}
```

## 44.实现字符串压缩

## 44.
```js
// abbccccaaa->a1b2c4a3
function compressWord(str) {
let res = '';
let arr = [];
for (let i = 0; i < str.length; i++) {
let cur = str[i];
const index = arr.indexOf(cur);
if (arr.length && index < 0) {
res += arr[0] + arr.length;
arr = [];
}
arr.push(cur);
}
if (arr.length) {
res += arr[0] + arr.length;
}
return res;
}
compressWord('abbccccaaa');
```

## 45.

## 46.
## 46.TS 练习嵌套 Awaited<T>

```ts
type MockAwaited<T extends Promise<unknown>> = T extends Promise<infer P>
? P extends Promise<unknown>
? MockAwaited<P>
: P
: T;
```

## 47.TS 练习根据 xx 类型提取类型的对象 FunctionKeys<T, Function>

> 关键词 as 映射
```ts
type TTP1 = {
name: string;
getName: () => void;
age: number;
};
type FunctionKeys<T, F> = {
[P in keyof T as T[P] extends F ? P : never]: T[P];
};
type Fun1 = FunctionKeys<TTP1, number>;
```

## 48.TS 练习索引类型转联合类型:IndexToUnion

```ts

```

## 49.TS 练习独一无二类型:Unique

## 47.
```ts

## 48.
```

## 50.TS 练习联合类型转交叉类型:UnionToIntersection

```ts

```
13 changes: 13 additions & 0 deletions docs/interview/experiences/19endHandwriting.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
title: 连续这么多手写,需要复盘和回归
order: 19
group:
order: 0
title: interview
nav:
order: 3
title: 'interview'
path: /interview
---

连续翻越前面几座大山,有什么收获吗?其实并没有
11 changes: 0 additions & 11 deletions docs/interview/experiences/19hotHandwriting.md

This file was deleted.

45 changes: 45 additions & 0 deletions docs/interview/experiences/22leetcodeB.md
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,8 @@ var deleteNode = function (head, val) {
};
```

## 10.括号生成

## [11.轮转数组](https://leetcode.cn/problems/rotate-array/?envType=study-plan-v2&envId=top-100-liked)

### 第一种方式
Expand Down Expand Up @@ -500,7 +502,46 @@ lengthOfLongestSubstring('abcabcbb');
## [15.乘积最大子数组](https://leetcode.cn/problems/maximum-product-subarray/)

```js
/**
* @param {number[]} nums
* @return {number}
*/
var maxProduct = function (nums) {
let max = Number.MIN_SAFE_INTEGER;
let imax = 1,
imin = 1;
for (let num of nums) {
if (num < 0) {
let tmp = imax;
imax = imin;
imin = tmp;
}
imax = Math.max(imax * num, num);
imin = Math.min(imin * num, num);
max = Math.max(max, imax);
}
return max;
};
```

### second

```js
var maxProduct = function (nums) {
let len = nums.length;
let dpMax = new Array(len).fill(1);
dpMax[0] = nums[0];
let dpMin = new Array(len).fill(1);
dpMin[0] = nums[0];
let max = nums[0];
for (let i = 1; i < len; i++) {
let cur = nums[i];
dpMax[i] = Math.max(dpMin[i - 1] * cur, Math.max(dpMax[i - 1] * cur, cur));
dpMin[i] = Math.min(dpMin[i - 1] * cur, Math.min(dpMax[i - 1] * cur, cur));
max = Math.max(max, dpMax[i]);
}
return max;
};
```

## [16.螺旋矩阵](https://leetcode.cn/problems/spiral-matrix/description/)
Expand Down Expand Up @@ -542,6 +583,8 @@ function matrix(nums) {
}
```

## 17.按照版本号对数组排序

## 18.翻转二叉树,二叉树的左右节点翻转

## [19.每日温度](https://leetcode.cn/problems/daily-temperatures/)
Expand Down Expand Up @@ -1235,6 +1278,8 @@ findLength([1, 2, 3, 2, 1], [3, 2, 1, 4, 7]);

## [45.最小覆盖子串](https://leetcode.cn/problems/minimum-window-substring/description/)

## 46.回文子串

## [47.和为 K 的子数组](https://leetcode.cn/problems/subarray-sum-equals-k/)

> (前缀和)
Expand Down
35 changes: 35 additions & 0 deletions docs/interview/experiences/practise/202404/0401.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,41 @@
* 8.最长重复子数组
*/

function maxMul(arr) {
let len = arr.length;
let dpMax = new Array(len).fill(1);
dpMax[0] = arr[0];
let dpMin = new Array(len).fill(1);
dpMin[0] = arr[0];
let max = arr[0];
for (let i = 1; i < len; i++) {
let cur = arr[i];
dpMax[i] = Math.max(dpMin[i - 1] * cur, cur, dpMax[i - 1] * cur);
dpMin[i] = Math.min(dpMin[i - 1] * cur, cur, dpMax[i - 1] * cur);
max = Math.max(dpMax[i], max);
}
return max;
}

function maxMul2(arr) {
let len = arr.length;
let max = 1;
let min = 1;
let res = Number.MIN_SAFE_INTEGER;
for (let i = 0; i < len; i++) {
let cur = arr[i];
if (cur < 0) {
let tmp = max;
max = min;
min = tmp;
}
min = Math.min(min * cur, cur);
max = Math.max(max * cur, cur);
res = Math.max(res, max);
}
return res;
}

class Route {
constructor() {
this.routes = [];
Expand Down
49 changes: 49 additions & 0 deletions docs/interview/experiences/practise/202404/0402.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,55 @@
/**
* 1.利用正则筛选只包含大小写字母的字符串
* 2.Object.assign(target, ...source)
* 3.两个数组的交集
* 4.字符串转换整数
* 5.字符串压缩
* 6.单词搜索
* 7.版本号进行排序
* 8.每日温度
* 9.最长连续重复子串
* 10.零钱兑换II
*/

function myAssign(target, ...source) {
if (typeof target != 'object') {
throw new TypeError('error');
}
source.forEach((item) => {
if (Object.keys(item).length) {
for (let key in item) {
if (item.hasOwnProperty(key)) {
target[key] = item[key];
}
}
}
});
return target;
}
Object.assign = myAssign;

// ['Abc', 'DeF', '123', '_ghI'];
function dataF(arr) {
return arr.filter((item) => /^[a-zA-Z]+$/.test(item)).map((item) => item.toUpperCase());
}
dataF(['Abc', 'DeF', '123', '_ghI']);
/**
* @param {number[]} nums1
* @param {number[]} nums2
* @return {number[]}
*/
var intersection = function (nums1, nums2) {
let a = [...new Set(nums1)];
let b = [...new Set(nums2)];
let m = new Map();
let ans = [];
for (let a1 of a) {
m.set(a1, 1);
}
for (let b1 of b) {
if (m.has(b1)) {
ans.push(b1);
}
}
return ans;
};
8 changes: 8 additions & 0 deletions docs/interview/experiences/practise/202404/0403.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* 1.最小栈
* 2.最大子序和/最大乘积子数组
* 3.字符串转换整数
* 4.判断子序列
* 5.跳跃游戏II
* 6.单词搜索
*/

0 comments on commit b7eabaf

Please sign in to comment.