# 引言

作为一个社会人,感觉自己在死瘦宅的路上愈行愈远,无法自拔~也越来越拖延 (懒癌晚期)

为了缓解下这种情况,决定工作学习之余没事刷刷题,而 LeetCode 就是一个不错的选择 (正好也用新入坑的 GO 语言写写代码试试水)~

谨以此文记录下 LeetCode 的刷题之路,也算是作为一个个人题解 Orz~

LeetCode

# 技巧处理

# 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::cinstd::cout 为了兼容 C , 保证在代码中同时出现 std::cinscanfstd::coutprintf 时输出不发生混乱,所以 C++ 用一个流缓冲区来同步 C 的标准流。通过 std::ios_base::sync_with_stdio 函数可以解除这种同步,让 std::cinstd::cout 不再经过缓冲区,自然就节省了许多时间。

解惑 cin.tie(nullptr)

std::cin 默认是与 std::cout 绑定的,所以每次操作的时候 (也就是调用 << 或者 >> ) 都要刷新 (调用 flush ), 这样增加了 IO 的负担,通过 tie(nullptr) 来解除 std::cinstd::cout 之间的绑定,来降低 IO 的负担使效率提升。

# 题解汇总

沉潜深度源自始终如一的专注。人的生命是有限的,精力是有限的,只有专注才能将人的力量发挥到极致。

题解链接题目名称难度
0001: 传送门 Click Here!Two SumEasy
0002: 传送门 Click Here!Add Two NumbersMedium
0003: 传送门 Click Here!Longest Substring Without Repeating CharactersMedium
0004: 传送门 Click Here!Median of Two Sorted ArraysHard
0005: 传送门 Click Here!Longest Palindromic SubstringMedium
0006: 传送门 Click Here!ZigZag ConversionMedium
0007: 传送门 Click Here!Reverse IntegerEasy
0008: 传送门 Click Here!String to Integer (atoi)Medium
0009: 传送门 Click Here!Palindrome NumberEasy
0010: 传送门 Click Here!Regular Expression MatchingHard
0011: 传送门 Click Here!Container With Most WaterMedium
0012: 传送门 Click Here!Integer to RomanMedium
0013: 传送门 Click Here!Roman to IntegerEasy
0014: 传送门 Click Here!Longest Common PrefixEasy
0015: 传送门 Click Here!3SumMedium
0016: 传送门 Click Here!3Sum ClosestMedium
0017: 传送门 Click Here!Letter Combinations of a Phone NumberMedium
0018: 传送门 Click Here!4SumMedium
0019: 传送门 Click Here!Remove Nth Node From End of ListMedium
0020: 传送门 Click Here!Valid ParenthesesEasy
0021: 传送门 Click Here!Merge Two Sorted ListsEasy
0022: 传送门 Click Here!Generate ParenthesesMedium
0023: 传送门 Click Here!Merge k Sorted ListsHard
0024: 传送门 Click Here!Swap Nodes in PairsMedium
0025: 传送门 Click Here!Reverse Nodes in k-GroupHard
0026: 传送门 Click Here!Remove Duplicates from Sorted ArrayEasy
0027: 传送门 Click Here!Remove ElementEasy
0028: 传送门 Click Here!Implement strStr()Easy
0029: 传送门 Click Here!Divide Two IntegersMedium
0030: 传送门 Click Here!Substring with Concatenation of All WordsHard
0031: 传送门 Click Here!Next PermutationEasy
0032: 传送门 Click Here!Longest Valid ParenthesesHard
更新于 阅读次数

请我喝[茶]~( ̄▽ ̄)~*

Seiun 微信支付

微信支付

Seiun 支付宝

支付宝