StarryNights

每一个你所后悔的现在,都有一个不够努力的曾经

站内检索

循着字句,邂逅星光

搜索文章标题与正文,直达命中的章节

开始一次轻盈的站内探索

从这些主题开始探索

输入关键词

可同时输入多个词语缩小范围

发现内容

在摘要中查看高亮的关键词

快速直达

点击文章或章节标题继续阅读

2.7k字4 分钟

# 引言 题目链接:https://leetcode.com/problems/reverse-nodes-in-k-group/ # 题目大意 给定一个链表, 一次反转链表的k个节点(每k个节点翻转一次), 最后返回修改后的列表。 Hint: k是正整数, 并且小于或等于链表的长度。如果节点数不是k的倍数, 那么最后的剩余节点应该保持不变。 Example Given this linked list: 1->2->3->4->5 For k = 2, you should return: 2->1
1.7k字2 分钟

# 引言 题目链接:https://leetcode.com/problems/swap-nodes-in-pairs/ # 题目大意 将链表中的节点两两交换。 Example Given 1->2->3->4, you should return the list as 2->1->4->3. Hint: Your algorithm should use only constant extra space. You may not modify the values in the list's
2.1k字3 分钟

# 引言 题目链接:https://leetcode.com/problems/merge-k-sorted-lists/description/ # 题目大意 合并k个已排序的链表并将其作为一个排序列表返回。 分析并描述其复杂性。 Example Input: [ 1->4->5, 1->3->4, 2->6 ] Output: 1->1->2->3->4->4->5->6 # 题解 # 一句话题解 直接借用21题 Merge Two Sorte
1.7k字2 分钟

# 引言 题目链接:https://leetcode.com/problems/generate-parentheses/description/ # 题目大意 给出数字n, 生成共有n对括号的所有正确的形式, 有效形式见例子 Example For example, given n = 3, a solution set is: [ "((()))", "(()())", "(())()", "()(())", &quo
1.5k字2 分钟

# 引言 题目链接:https://leetcode.com/problems/merge-two-sorted-lists/description/ # 题目大意 合并两个有序链表并返回一个新的列表。 Example Input: 1->2->4, 1->3->4 Output: 1->1->2->3->4->4 # 题解 # 一句话题解 简单归并排序(由于这儿只有两条链表还是有序的, 所以时间复杂度退化为) # 复杂度 时间复杂度 O(n) 空间复杂度 O(1) # AC代
1.7k字2 分钟

# 引言 题目链接:https://leetcode.com/problems/valid-parentheses/description/ # 题目大意 输入一个由各种括号组成的字符串, 按照如下规则判断字符串是否有效 条件: 开括号必须由相同类型的括号来关闭, 即'('由')'关闭、'['由']'关闭, '{'由'}'关闭. 按照正确的顺序打开的括号必须按照同样顺序关闭。 Hont: Note that an empty strin
1.5k字2 分钟

# 引言 题目链接:https://leetcode.com/problems/remove-nth-node-from-end-of-list/description/ # 题目大意 给定一个链表和数字n, 删除链表倒数第n个节点并返回结果链表 Hint: Given n will always be valid. Example Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from th
3.5k字5 分钟

# 引言 题目链接:https://leetcode.com/problems/4sum/description/ # 题目大意 给出一个包含n个整数的数组nums以及一个目标值target, 这个数组是否存在有元素a,b,c,d使得a + b + c + d = target, 找出所有满足条件的a,b,c,d的组合 Example Given array nums = [1, 0, -1, 0, -2, 2], and target = 0. A solution set is: [ [-1
2.9k字4 分钟

# 引言 题目链接:https://leetcode.com/problems/letter-combinations-of-a-phone-number/description/ # 题目大意 题目给出的图和九键拼音输入法类似, 2对应的是abc,3对应的def, 这样。现在给出一个数字序列, 要求输出这个数字序列可以打出的所有字符串组合。 Example Input: "23" Output: ["ad", "ae", "af", "bd
1.7k字2 分钟

# 引言 题目链接:https://leetcode.com/problems/container-with-most-water/description/ # 题目大意 给定n个非负整数a1,a2,...,an, 其中每个代表一个点坐标(i,ai), 通过每个点做x轴的垂直线, 最后取任意两条线, 使得两条线与x轴所构成的容器能装最多的水。 Note: You may not slant the container and n is at least 2.(即水的面积不是容器的面积, 而是最大矩形的面积, 并且一定有解) Exam