# 引言
作为一个社会人,感觉自己在死瘦宅的路上愈行愈远,无法自拔~也越来越拖延 (懒癌晚期)
为了缓解下这种情况,决定工作学习之余没事刷刷题,而 LeetCode 就是一个不错的选择 (正好也用新入坑的 GO 语言写写代码试试水)~
谨以此文记录下 LeetCode 的刷题之路,也算是作为一个个人题解 Orz~

# 技巧处理
# C++ 输入输出加速
在刷 LeetCode 的时候,习惯性看看最优时间的大佬们的解法,偶然发现有些题同样的方法别人运行时间就要低上不少,然后发现这些提交一般都有如下这个 Lambda 表达式。
static const auto __________ = []() | |
{ | |
ios::sync_with_stdio(false); | |
cin.tie(nullptr); | |
return nullptr; | |
}(); |
仔细看了看 LeetCode 对于使用 C++ 提交的人,输入输出默认使用的 C++ 的 io , 而不是 C 的,上面 Lambda 捕获,则可以用来解除 C++ 为了兼容 C 而采取的缓存同步机制,提升 cin , cout 的速度
解惑 ios::sync_with_stdio(false)
因为 C++ 中的 std::cin 和 std::cout 为了兼容 C , 保证在代码中同时出现 std::cin 和 scanf 或 std::cout 和 printf 时输出不发生混乱,所以 C++ 用一个流缓冲区来同步 C 的标准流。通过 std::ios_base::sync_with_stdio 函数可以解除这种同步,让 std::cin 和 std::cout 不再经过缓冲区,自然就节省了许多时间。
解惑 cin.tie(nullptr)
std::cin 默认是与 std::cout 绑定的,所以每次操作的时候 (也就是调用 << 或者 >> ) 都要刷新 (调用 flush ), 这样增加了 IO 的负担,通过 tie(nullptr) 来解除 std::cin 和 std::cout 之间的绑定,来降低 IO 的负担使效率提升。
# 题解汇总
沉潜深度源自始终如一的专注。人的生命是有限的,精力是有限的,只有专注才能将人的力量发挥到极致。
| 题解链接 | 题目名称 | 难度 |
|---|---|---|
| 0001: 传送门 Click Here! | Two Sum | Easy |
| 0002: 传送门 Click Here! | Add Two Numbers | Medium |
| 0003: 传送门 Click Here! | Longest Substring Without Repeating Characters | Medium |
| 0004: 传送门 Click Here! | Median of Two Sorted Arrays | Hard |
| 0005: 传送门 Click Here! | Longest Palindromic Substring | Medium |
| 0006: 传送门 Click Here! | ZigZag Conversion | Medium |
| 0007: 传送门 Click Here! | Reverse Integer | Easy |
| 0008: 传送门 Click Here! | String to Integer (atoi) | Medium |
| 0009: 传送门 Click Here! | Palindrome Number | Easy |
| 0010: 传送门 Click Here! | Regular Expression Matching | Hard |
| 0011: 传送门 Click Here! | Container With Most Water | Medium |
| 0012: 传送门 Click Here! | Integer to Roman | Medium |
| 0013: 传送门 Click Here! | Roman to Integer | Easy |
| 0014: 传送门 Click Here! | Longest Common Prefix | Easy |
| 0015: 传送门 Click Here! | 3Sum | Medium |
| 0016: 传送门 Click Here! | 3Sum Closest | Medium |
| 0017: 传送门 Click Here! | Letter Combinations of a Phone Number | Medium |
| 0018: 传送门 Click Here! | 4Sum | Medium |
| 0019: 传送门 Click Here! | Remove Nth Node From End of List | Medium |
| 0020: 传送门 Click Here! | Valid Parentheses | Easy |
| 0021: 传送门 Click Here! | Merge Two Sorted Lists | Easy |
| 0022: 传送门 Click Here! | Generate Parentheses | Medium |
| 0023: 传送门 Click Here! | Merge k Sorted Lists | Hard |
| 0024: 传送门 Click Here! | Swap Nodes in Pairs | Medium |
| 0025: 传送门 Click Here! | Reverse Nodes in k-Group | Hard |
| 0026: 传送门 Click Here! | Remove Duplicates from Sorted Array | Easy |
| 0027: 传送门 Click Here! | Remove Element | Easy |
| 0028: 传送门 Click Here! | Implement strStr() | Easy |
| 0029: 传送门 Click Here! | Divide Two Integers | Medium |
| 0030: 传送门 Click Here! | Substring with Concatenation of All Words | Hard |
| 0031: 传送门 Click Here! | Next Permutation | Easy |
| 0032: 传送门 Click Here! | Longest Valid Parentheses | Hard |