Jerring


  • 首页

  • 标签

  • 分类

  • 归档

LeetCode21-合并两个有序链表

发表于 2018-11-05 | 分类于 LeetCode

题目链接

英文链接:https://leetcode.com/problems/merge-two-sorted-lists/

中文链接:https://leetcode-cn.com/problems/merge-two-sorted-lists/

题目详述

将两个有序链表合并为一个新的有序链表并返回。新链表是通过拼接给定的两个链表的所有节点组成的。

示例:

1
2
输入:1->2->4, 1->3->4
输出:1->1->2->3->4->4
阅读全文 »

LeetCode240-搜索二维矩阵II

发表于 2018-11-04 | 分类于 LeetCode

题目链接

英文链接:https://leetcode.com/problems/search-a-2d-matrix-ii/

中文链接:https://leetcode-cn.com/problems/search-a-2d-matrix-ii/

题目详述

编写一个高效的算法来搜索 m x n 矩阵 matrix 中的一个目标值 target。该矩阵具有以下特性:

  • 每行的元素从左到右升序排列。
  • 每列的元素从上到下升序排列。

示例:

现有矩阵 matrix 如下:

1
2
3
4
5
6
7
[
[1, 4, 7, 11, 15],
[2, 5, 8, 12, 19],
[3, 6, 9, 16, 22],
[10, 13, 14, 17, 24],
[18, 21, 23, 26, 30]
]

给定 target = 5,返回 true。

给定 target = 20,返回 false。

阅读全文 »

LeetCode237-删除链表中的结点

发表于 2018-11-04 | 分类于 LeetCode

题目链接

英文链接:https://leetcode.com/problems/delete-node-in-a-linked-list/

中文链接:https://leetcode-cn.com/problems/delete-node-in-a-linked-list/

题目详述

请编写一个函数,使其可以删除某个链表中给定的(非末尾)节点,你将只被给定要求被删除的节点。

现有一个链表 – head = [4,5,1,9],它可以表示为:

1
4 -> 5 -> 1 -> 9

示例 1:

1
2
3
输入: head = [4,5,1,9], node = 5
输出: [4,1,9]
解释: 给定你链表中值为 5 的第二个节点,那么在调用了你的函数之后,该链表应变为 4 -> 1 -> 9.

示例 2:

1
2
3
输入: head = [4,5,1,9], node = 1
输出: [4,5,9]
解释: 给定你链表中值为 1 的第三个节点,那么在调用了你的函数之后,该链表应变为 4 -> 5 -> 9.

说明:

  • 链表至少包含两个节点。
  • 链表中所有节点的值都是唯一的。
  • 给定的节点为非末尾节点并且一定是链表中的一个有效节点。
  • 不要从你的函数中返回任何结果。
阅读全文 »

LeetCode74-搜索二维矩阵

发表于 2018-11-04 | 分类于 LeetCode

题目链接

英文链接:https://leetcode.com/problems/search-a-2d-matrix/

中文链接:https://leetcode-cn.com/problems/search-a-2d-matrix/

题目详述

编写一个高效的算法来判断 m x n 矩阵中,是否存在一个目标值。该矩阵具有如下特性:

  • 每行中的整数从左到右按升序排列。
  • 每行的第一个整数大于前一行的最后一个整数。

示例 1:

1
2
3
4
5
6
7
8
输入:
matrix = [
[1, 3, 5, 7],
[10, 11, 16, 20],
[23, 30, 34, 50]
]
target = 3
输出: true

示例 2:

1
2
3
4
5
6
7
8
输入:
matrix = [
[1, 3, 5, 7],
[10, 11, 16, 20],
[23, 30, 34, 50]
]
target = 13
输出: false
阅读全文 »

LeetCode34-在排序数组中查找元素的第一个和最后一个位置

发表于 2018-11-04 | 分类于 LeetCode

题目链接

英文链接:https://leetcode.com/problems/find-first-and-last-position-of-element-in-sorted-array/

中文链接:https://leetcode-cn.com/problems/find-first-and-last-position-of-element-in-sorted-array/

题目详述

给定一个按照升序排列的整数数组 nums,和一个目标值 target。找出给定目标值在数组中的开始位置和结束位置。

你的算法时间复杂度必须是 O(log n) 级别。

如果数组中不存在目标值,返回 [-1, -1]。

示例 1:

1
2
输入: nums = [5,7,7,8,8,10], target = 8
输出: [3,4]

示例 2:

1
2
输入: nums = [5,7,7,8,8,10], target = 6
输出: [-1,-1]
阅读全文 »

LeetCode35-搜索插入位置

发表于 2018-11-04 | 分类于 LeetCode

题目链接

英文链接:https://leetcode.com/problems/search-insert-position/

中文链接:https://leetcode-cn.com/problems/search-insert-position/

题目详述

给定一个排序数组和一个目标值,在数组中找到目标值,并返回其索引。如果目标值不存在于数组中,返回它将会被按顺序插入的位置。

你可以假设数组中无重复元素。

示例 1:

1
2
输入: [1,3,5,6], 5
输出: 2

示例 2:

1
2
输入: [1,3,5,6], 2
输出: 1

示例 3:

1
2
输入: [1,3,5,6], 7
输出: 4

示例 4:

1
2
输入: [1,3,5,6], 0
输出: 0
阅读全文 »

LeetCode154-寻找旋转排序数组中的最小值II

发表于 2018-11-03 | 分类于 LeetCode

题目链接

英文链接:https://leetcode.com/problems/find-minimum-in-rotated-sorted-array-ii/

中文链接:https://leetcode-cn.com/problems/find-minimum-in-rotated-sorted-array-ii/

题目详述

假设按照升序排序的数组在预先未知的某个点上进行了旋转。

( 例如,数组 [0,1,2,4,5,6,7] 可能变为 [4,5,6,7,0,1,2] )。

请找出其中最小的元素。

注意数组中可能存在重复的元素。

示例 1:

1
2
输入: [1,3,5]
输出: 1

示例 2:

1
2
输入: [2,2,2,0,1]
输出: 0

说明:

  • 这道题是 寻找旋转排序数组中的最小值 的延伸题目。
  • 允许重复会影响算法的时间复杂度吗?会如何影响,为什么?
阅读全文 »

LeetCode153-寻找旋转排序数组中的最小值

发表于 2018-11-02 | 分类于 LeetCode

题目链接

英文链接:https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/

中文链接:https://leetcode-cn.com/problems/find-minimum-in-rotated-sorted-array/

题目详述

假设按照升序排序的数组在预先未知的某个点上进行了旋转。

( 例如,数组 [0,1,2,4,5,6,7] 可能变为 [4,5,6,7,0,1,2] )。

请找出其中最小的元素。

你可以假设数组中不存在重复元素。

示例 1:

1
2
输入: [3,4,5,1,2]
输出: 1

示例 2:

1
2
输入: [4,5,6,7,0,1,2]
输出: 0
阅读全文 »

LeetCode81-搜索旋转排序数组II

发表于 2018-11-01 | 分类于 LeetCode

题目链接

英文链接:https://leetcode.com/problems/search-in-rotated-sorted-array-ii/

中文链接:https://leetcode-cn.com/problems/search-in-rotated-sorted-array-ii/

题目详述

假设按照升序排序的数组在预先未知的某个点上进行了旋转。

( 例如,数组 [0,0,1,2,2,5,6] 可能变为 [2,5,6,0,0,1,2] )。

编写一个函数来判断给定的目标值是否存在于数组中。若存在返回 true,否则返回 false。

示例 1:

1
2
输入: nums = [2,5,6,0,0,1,2], target = 0
输出: true

示例 2:

1
2
输入: nums = [2,5,6,0,0,1,2], target = 3
输出: false

进阶:

  • 这是 搜索旋转排序数组 的延伸题目,本题中的 nums 可能包含重复元素。
  • 这会影响到程序的时间复杂度吗?会有怎样的影响,为什么?
阅读全文 »

LeetCode33-搜索旋转排序数组

发表于 2018-10-31 | 分类于 LeetCode

题目链接

英文链接:https://leetcode.com/problems/search-in-rotated-sorted-array/

中文链接:https://leetcode-cn.com/problems/search-in-rotated-sorted-array/

题目详述

假设按照升序排序的数组在预先未知的某个点上进行了旋转。

( 例如,数组 [0,1,2,4,5,6,7] 可能变为 [4,5,6,7,0,1,2] )。

搜索一个给定的目标值,如果数组中存在这个目标值,则返回它的索引,否则返回 -1 。

你可以假设数组中不存在重复的元素。

你的算法时间复杂度必须是 O(log n) 级别。

示例 1:

1
2
输入: nums = [4,5,6,7,0,1,2], target = 0
输出: 4

示例 2:

1
2
输入: nums = [4,5,6,7,0,1,2], target = 3
输出: -1
阅读全文 »
1…454647
Jerring

Jerring

Talk is cheap, show me the code.

462 日志
4 分类
24 标签
© 2019 Jerring
由 Hexo 强力驱动
|
主题 — NexT.Muse v5.1.4