正文
ARTS 第 35 周
每周完成一个 ARTS:
Algorithm: 每周至少做一个 LeetCode 的算法题
Review: 阅读并点评至少一篇英文技术文章
Tips: 学习至少一个技术技巧
Share: 分享一篇有观点和思考的技术文章
Contents
- Algorithm: 83. Remove Duplicates from Sorted List
- Review: 10 Things To Boost Your Workflow In Visual Studio Code
- Tip: VS Code 中配置 snippets
- Share: 打字速度测试与练习
Algorithm
83. Remove Duplicates from Sorted List
题目:83. Remove Duplicates from Sorted List
难度:Easy
题意:Given a sorted linked list, delete all duplicates such that each element appear only once.
示例 1:
Input: 1->1->2
Output: 1->2
示例 2:
Input: 1->1->2->3->3
Output: 1->2->3
解法:
本题解法非常直接,遍历整个链表,当当前对象的之和下一个对象的值相同时,将下一个对象指向下下一个对象,这样就删去了下一个对象,否则将当前对象指向下一个对象。
代码:
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution:
def deleteDuplicates(self, head: ListNode) -> ListNode:
current = head
while current != None and current.next != None:
if current.val == current.next.val:
current.next = current.next.next
else:
current = current.next
return head
时间复杂度 O(n),空间复杂度 O(1)。
Review
10 Things To Boost Your Workflow In Visual Studio Code
本周阅读了一篇 Medium 上名为《10 Things To Boost Your Workflow In Visual Studio Code》的文章。文章讲述了她作为前端开发者,在使用 VS Code 开发时提升编码效率常用的十个小技巧。我认为这些技巧不仅适用于前端,更适用于大部分 VS Code 的用户,将其罗列如下:
- Snippets
- IntelliSense
- Integrated Terminal
- Peeking, References, and Update Symbol
- Code Formatters and Tech Debt Trackers
- Key Bindings
- Zen Mode
- Git
- Debugger
- Live Share
Tips
VS Code 中配置 snippets
上一部分讲了 VS Code 的几个实用技巧,这一部分我给大家分享一下如何在 VS Code 中配置你自己的 Snippets,即「代码片段」。
snippet 指的是「重复使用的代码片段」,我们只要输入几个特定字符,就可以在 VS Code 的帮助下输入预定义好的代码模板,并且 VS Code 提供了在「模板中插入预定义光标位置」的功能,方便我们在不同位置进行跳转。
下面我们介绍如何使用这一功能。
首先,按下「Shift+Command+P」,输入「snippet」,选择「Preferences: Configure User Snippets」:

接下来,你可以仅针对你这个项目设置代码片段,或者对全局设置代码片段,接着输入你想要建立的代码片段文件的名字。这样 VS Code 会为你生成一个后缀为.code-snippets 的代码片段配置文件,并将其存储在本项目(或全局)的 .vscode 文件夹下。打开这个文件,你会看到有一些注释和一个针对 JS 的示例,建议反注释掉这个 JS 的示例,你就会瞬间明白 VS Code 的 snippet 需要怎样配置了。
// Example:
"Print to console": {
"scope": "javascript,typescript",
"prefix": "log",
"body": [
"console.log('$1');",
"$2"
],
"description": "Log output to console"
},
下面是对这个 JSON 文件的一些解释:
scope:作用域,就是这个代码片段适用的语言prefix:前缀,指这个代码片段能在 IntelliSense 中的关键字body:主体,就是你的代码模板了description:描述,你对这个代码片段的描述,这个描述会出现在 IntelliSense 中
关于除了 body 外的其他三个其实没有什么好说的,下面来讲一下关于 body 的配置。
如果你的代码模板是一大段,那么你需要使用方括号将它括起来,并且每一排都单读用双引号和逗号隔开,就像示例中那样,并且如果有空行,也要单独加入 "", 占位。$1、$2 这些是预定义的光标位置「Tabstops」,在插入代码模板之后,你可以按 TAB 键在这些光标位置间跳转,相同序号的 Tabstops 会同步进行更新。
另外你还可以插入变量,使用 $variable_name 插入,VS Code 提供了以下一些可选变量:
TM_SELECTED_TEXTThe currently selected text or the empty stringTM_CURRENT_LINEThe contents of the current lineTM_CURRENT_WORDThe contents of the word under cursor or the empty stringTM_LINE_INDEXThe zero-index based line numberTM_LINE_NUMBERThe one-index based line numberTM_FILENAMEThe filename of the current documentTM_FILENAME_BASEThe filename of the current document without its extensionsTM_DIRECTORYThe directory of the current documentTM_FILEPATHThe full file path of the current documentCLIPBOARDThe contents of your clipboardWORKSPACE_NAMEThe name of the opened workspace or folderCURRENT_YEARThe current yearCURRENT_YEAR_SHORTThe current year’s last two digitsCURRENT_MONTHThe month as two digits (example ‘02’)CURRENT_MONTH_NAMEThe full name of the month (example ‘July’)CURRENT_MONTH_NAME_SHORTThe short name of the month (example ‘Jul’)CURRENT_DATEThe day of the monthCURRENT_DAY_NAMEThe name of day (example ‘Monday’)CURRENT_DAY_NAME_SHORTThe short name of the day (example ‘Mon’)CURRENT_HOURThe current hour in 24-hour clock formatCURRENT_MINUTEThe current minuteCURRENT_SECONDThe current secondCURRENT_SECONDS_UNIXThe number of seconds since the Unix epochBLOCK_COMMENT_STARTExample output: in PHP /* or in HTML<!--BLOCK_COMMENT_ENDExample output: in PHP */ or in HTML-->LINE_COMMENTExample output: in PHP // or in HTML<!-- -->
如下的代码片段将在 JavaScript 中插入 /* Hello World */,在 HTML 中插入 <!-- Hello World -->:
{
"hello": {
"scope": "javascript,html",
"prefix": "hello",
"body": "$BLOCK_COMMENT_START Hello World $BLOCK_COMMENT_END"
}
}
更多信息请查阅官方文档:https://code.visualstudio.com/docs/editor/userdefinedsnippets.
Share
打字速度测试与练习
分享一个打字速度测试的网站:ratatype.com.
通常打字的标准是:达到盲打入门水平,键速=1~2键/秒,或者120字符/秒以上,正确率100%。在实际英语环境中,各公司的要求一般至少不低于 35 个单词每分钟,如果是前台一般要求至少 45 个单词每分钟,而数据录入员这样的职位要求 45-50 个单词每分钟,这是在英语国家中的实际应用标准。
分享一个打字练习网站:typing-lessons.org.