forked from hovinghuang/fe-agorithm-interview
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e2401e3
commit 96a0e7a
Showing
14 changed files
with
252 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/00-codetop-fontend-100/01-length-of-longest-substring.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// 待更新,敬请期待…… |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// 待更新 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// 待更新 |
Oops, something went wrong.