无论是在 Web2 还是 Web3 领域,熟练掌握数据结构、算法和解答 LeetCode 题目都非常重要,这不仅是为了找工作,更是为了打下良好的计算机科学基础。
许多开发者都知道他们应该在 LeetCode(或者 HackerRank、Codecademy 或 Codewars)上进行练习,但如果你还没有开始,这可能会让人感到非常望而生畏。
你应该从哪些 LeetCode 题目开始?应该按照什么顺序进行?
克服开始的心理障碍
没有什么比打开这些网站,随机挑选一道标记为简单的题目,然后卡住更让人受打击的了。现在你必须耗费三倍的精力:寻找合适的题目、解决它,并且还要克服心理暗示,不要去怀疑自己是不是选错了题目,或者根本不是考试的料。
我们建议的做法是,从那些简单到不可思议的 LeetCode 题目开始。说真的,下面这个挑战怎么样?
https://leetcode.com/problems/add-two-integers/
func sum(num1 int, num2 int) int {
}
计算两个整数之和的简单编程问题
没那么可怕,对吧?
专注于语言的核心
市面上有非常多的数据结构和算法。有树、链表、堆、队列、图、有向图等等!为了避免被过多的选择淹没,最好先专注于几乎所有现代语言内置的数据结构。
- 数组
- 字符串
- 嵌套数组(二维数组)
- 哈希表
大多数语言允许你在不导入任何库的情况下使用这些数据结构。
要使用队列(Queue)或堆(Heap)等数据结构,你通常需要导入某种库。尽管技术日新月异,但编程语言已经存在了几十年。它们经过演进,让常见的操作变得简单。在其他条件相同的情况下,如果一种语言使用起来需要做更多额外的工作,它最终会失宠。
翻转二叉树并不是一件常见的事情。但是操作字符串和数组却非常普遍,因此它们被直接内置在语言中。
如果你不知道如何在使用一种语言时完成这些基础操作,你就不算懂得用这门语言编程。学习树、图和队列等知识并不特定于某种语言。但如果你不能在 JavaScript 中遍历一个数组,你就不能说你懂 JavaScript。
我们整理的这份题目清单旨在确保你能熟练掌握语言的核心基础。这些问题将为你日后学习更高级的主题打下坚实的基础。
优先关注逻辑与问题解决
算法的名字可能会让人心生畏惧,它们通常是由鲜为人知的欧洲人名与深奥的应用场景拼接而成。Floyd-Warshall?Dijkstra’s algorithm?Fisher-Yates?
你可以把这些留到以后再学。
但你绝对必须能够完成那些甚至算不上“算法”的基础操作。
例如,给定一个井字棋(tic-tac-toe)棋盘,你能判断游戏是否结束吗?你不需要任何花哨的算法来完成这件事。如果你在这个基本任务上都感到吃力,那么在面对上面列出的更高级算法时,你将会感到非常困难。
我们在这里列出的问题不需要任何特殊的技巧来解决。在你去挑战更多大学课程级别的技术之前,先学会应用基本逻辑和常识性的解决方案。
这些是不是太简单了?
也许你并不是本文的目标受众,但你会惊讶地发现,有大量自称为开发者的人其实写不出 fizz buzz。我们亲眼见证了这一点。当你申请我们的项目时,你会很快收到一封带有编程测试链接的电子邮件。其中一道题就是 fizz buzz。而这道题的失败率非常高。
也许是因为紧张,或者是以前从未参加过编程测试。但如果你连一次编程测试都没有练习过,这绝对是对你自己不利的。
掌握这些足以通过编程面试吗?
如果你能解决所有这些问题,你可能也能找到一份工作!这会是在一家筛选不那么严格的公司里的入门级岗位。但不管怎样,这并非不可能。
使用这些题目不需要付费吗?
我们只包含了免费版本中的题目。
版权声明
鉴于我们曾在其他软件培训项目中遇到过抄袭问题,本作品整体采用知识共享非商业性使用协议(Creative Commons NonCommercial License)进行许可。
热身题(播放列表)
- https://leetcode.com/problems/convert-the-temperature/
- https://leetcode.com/problems/add-two-integers/
- https://leetcode.com/problems/smallest-even-multiple/
- https://leetcode.com/problems/final-value-of-variable-after-performing-operations/
- https://leetcode.com/problems/count-of-matches-in-tournament/
- https://leetcode.com/problems/number-of-common-factors/
- https://leetcode.com/problems/xor-operation-in-an-array/
字符串(播放列表):
- https://leetcode.com/problems/length-of-last-word/
- https://leetcode.com/problems/to-lower-case/
- https://leetcode.com/problems/to-lower-case/ (只需反向操作即可)
- https://leetcode.com/problems/reverse-string/ (不要使用双指针)
- https://leetcode.com/problems/valid-palindrome/
- https://leetcode.com/problems/count-vowel-substrings-of-a-string/ (不要使用哈希表)
- https://leetcode.com/problems/repeated-substring-pattern/
- https://leetcode.com/problems/defanging-an-ip-address/
- https://leetcode.com/problems/determine-color-of-a-chessboard-square/
- https://leetcode.com/problems/add-digits/
- https://leetcode.com/problems/jewels-and-stones/
- https://leetcode.com/problems/roman-to-integer/
数组(播放列表):
- https://leetcode.com/problems/fizz-buzz/
- https://leetcode.com/problems/check-if-array-is-sorted-and-rotated/
- https://leetcode.com/problems/sort-an-array/ (忽略 LeetCode 的提示,使用内置功能)
- https://leetcode.com/problems/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence/
- https://leetcode.com/problems/subtract-the-product-and-sum-of-digits-of-an-integer/
- https://leetcode.com/problems/find-first-palindromic-string-in-the-array/
- https://leetcode.com/problems/running-sum-of-1d-array/
- https://leetcode.com/problems/merge-two-sorted-lists/
- https://leetcode.com/problems/find-greatest-common-divisor-of-array/
- https://leetcode.com/problems/maximum-number-of-words-found-in-sentences/
- https://leetcode.com/problems/final-value-of-variable-after-performing-operations/
- https://leetcode.com/problems/shuffle-the-array/
- https://leetcode.com/problems/shuffle-string/
- https://leetcode.com/problems/cells-in-a-range-on-an-excel-sheet/
- https://leetcode.com/problems/minimum-sum-of-four-digit-number-after-splitting-digits/
- https://leetcode.com/problems/decompress-run-length-encoded-list/
二维数组(播放列表):
- https://leetcode.com/problems/richest-customer-wealth/
- https://leetcode.com/problems/flipping-an-image/
- https://leetcode.com/problems/lucky-numbers-in-a-matrix/
- https://leetcode.com/problems/shift-2d-grid/
- https://leetcode.com/problems/available-captures-for-rook/
哈希表(播放列表):
- https://leetcode.com/problems/jewels-and-stones/
- https://leetcode.com/problems/decode-the-message/
- https://leetcode.com/problems/unique-morse-code-words/
- https://leetcode.com/problems/check-if-the-sentence-is-pangram/
- https://leetcode.com/problems/first-letter-to-appear-twice/
- https://leetcode.com/problems/sum-of-unique-elements/
- https://leetcode.com/problems/merge-similar-items/
- https://leetcode.com/problems/divide-array-into-equal-pairs/
- https://leetcode.com/problems/destination-city/
- https://leetcode.com/problems/number-of-good-pairs
喜欢本文的内容吗?请查看我们的免费 Solidity 课程。
原载于 2022 年 12 月 8 日