1.5k 2 分钟

# 引言 题目链接: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...
1.2k 2 分钟

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

# 引言 题目链接: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) 空间复杂度...
1.4k 2 分钟

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

# 引言 题目链接: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, 0, 0, 1], [-2, -1, 1, 2], [-2, 0,...
2.3k 3 分钟

# 引言 题目链接:https://leetcode.com/problems/letter-combinations-of-a-phone-number/description/ # 题目大意 题目给出的图和九键拼音输入法类似,2 对应的是 abc,3 对应的 def, 这样。现在给出一个数字序列,要求输出这个数字序列可以打出的所有字符串组合。 Example Input: "23" Output: ["ad", "ae", "af", "bd", "be",...
1.2k 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.(即水的面积不是容器的面积,而是最大矩形的面积,并且一定有解) Example Input:...
2.3k 3 分钟

# 引言 题目链接:https://leetcode.com/problems/3sum-closest/description/ # 题目大意 给出一个包含 n 个整数的数组 nums 和一个目标数字 target, 在数组中找到三个整数使得它们的总和最接近目标 target, 输出这个最接近目标值的数字 Example Given array nums = [-1, 2, 1, -4], and target = 1. The sum that is closest to the target is 2. (-1 + 2 + 1 = 2). # 题解 这题其实是第 15...
2.3k 3 分钟

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