Skip to content

Commit

Permalink
update:配置TS环境,完成第一份题解
Browse files Browse the repository at this point in the history
  • Loading branch information
hovinghuang committed Apr 12, 2022
1 parent e2401e3 commit 96a0e7a
Show file tree
Hide file tree
Showing 14 changed files with 252 additions and 85 deletions.
25 changes: 18 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
# fe-agorithm-interview
前端算法面试常考题目解析。
<h1>前端算法面试高频题库&题目解析</h1>

一站式解决前端面试遇到的算法问题
<h4>一站式解决前端面试遇到的算法问题,咱们只专注于前端高频算法。</h4>

解决痛点:
(1)LeetCode 题目太多,不知从何刷起?
(2)面试题目有些是前端常考,有些是后端常考?想把时间花在刀刃上怎么办?
(3)其他仓库为了吸引关注,会尽量把所有题目列的很’全‘(刷不完那一种),根本没有照顾到求职心切的人的心情?
<p>解决痛点:
<br>
(1)LeetCode 题目太多,不知从何刷起?面试题目有些是前端常考,有些是后端常考?
<br>
答:本站参照 CodeTop 上的前端算法题目考察频度,抽取前100道题,知道你时间宝贵,咱们要把时间花在刀刃上。
<br>
(2)leetcode 上面的题解鱼龙混杂,有些直接题目直接贴代码,没有任何分析过程,看不懂?
<br>
答:本站会带你理解题目,并且给出解题思路,分析时间&空间复杂度,一题多解,带你彻底搞懂。
<br>
(3)github 有些仓库为了吸引关注数目,会尽量把所有题目列的很’全‘(刷不完那一种),根本没有照顾到求职心切的人的心情?
<br>
答:本站只做专精,不搞大而全。根据考试频率划分层次,让你做题时心里有数,减少求职者刷算法时的心理负担。
<br>
使用方法:待补充
</p>
158 changes: 158 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"css-loader": "^6.7.1",
"html-webpack-plugin": "^5.5.0",
"style-loader": "^3.3.1",
"ts-loader": "^9.2.8",
"typescript": "^4.6.3",
"webpack": "^5.72.0",
"webpack-cli": "^4.9.2",
"webpack-dev-server": "^4.8.1"
Expand Down
42 changes: 42 additions & 0 deletions src/00-codetop-fontend-100/01-length-of-longest-substring.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* 题目名称:无重复字符的最长子串(类似题目:最长无重复子数组)
* leetcode 题目: https://leetcode-cn.com/problems/longest-substring-without-repeating-characters/
* leetcode 题解: https://leetcode-cn.com/problems/longest-substring-without-repeating-characters/solution/by-hovinghuang-qugo/
* 牛客网 题目: https://www.nowcoder.com/practice/b56799ebfd684fb394bd315e89324fb4?tpId=295&tqId=1008889&ru=/exam/oj&qru=/ta/format-top101/question-ranking&sourceUrl=%2Fexam%2Foj%3Ftab%3D%25E7%25AE%2597%25E6%25B3%2595%25E7%25AF%2587%26topicId%3D295
* 牛客网 题解: https://blog.nowcoder.net/n/fce41b44190449f18c605a0a41db9c78
*/

/**
* 解法一:滑动窗口(reduce累加器)
* 思路:
* (1)先判断字符串 s 的长度,如果 s.length <= 1 直接返回 s.length
* (2)将字符串 s 转成数组,这样就可以用数组的 reduce 累加器
* (3)reduce 滑动窗口过程处理(详细过程看以下代码),返回最长子串的长度 maxLen
* 时间复杂度:O(n),n 代表字符串长度,reduce 会将字符串的每一个字符都遍历一遍
* 空间复杂度:O(n),n 代表字符串长度,将字符串转成了数组(额外空间)
*/
function lengthOfLongestSubstring(s: string): number {
if (s.length <= 1) return s.length

let maxLen = 0
const strArr = s.split('')

strArr.reduce((total, value) => {
const index = total.indexOf(value)

// 拼接到 total 尾部
total += value

if (index === -1) {
// 如果该字符没有在 total 中出现过,获取目前为止滑动窗口的最大值
maxLen = Math.max(total.length, maxLen)
} else {
// 如果该字符有在 total 中出现过,则剔除掉 total 中 0 ~ index 的字符
total = total.slice(index + 1)
}

return total
}, '')

return maxLen
};
4 changes: 0 additions & 4 deletions src/01-nowcoder-top-101/01-reverse-link-list.js

This file was deleted.

1 change: 1 addition & 0 deletions src/01-nowcoder-top-101/01-reverse-link-list.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// 待更新,敬请期待……
4 changes: 0 additions & 4 deletions src/02-jianzhi-offer-81/01-reverse-link-list.js

This file was deleted.

1 change: 1 addition & 0 deletions src/02-jianzhi-offer-81/01-reverse-link-list.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// 待更新
4 changes: 0 additions & 4 deletions src/03-dachang/01-reverse-link-list.js

This file was deleted.

1 change: 1 addition & 0 deletions src/03-leetcode-100/01-reverse-link-list.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// 待更新
Loading

0 comments on commit 96a0e7a

Please sign in to comment.